跳至主要内容

此浏览器不再受支持。

请升级到 Microsoft Edge 以使用最新的功能、安全更新和技术支持。

下载 Microsoft Edge 有关 Internet Explorer 和 Microsoft Edge 的详细信息
microsoft-foundry.rest.security.o-auth2-auth

Threads, Assistants

Update a thread

POST /openai/v1/threads/{thread_id}

Updates a thread with the supplied changes.

路径参数

thread_id string 必需

The ID of the thread to modify. Only the metadata can be modified.

请求正文

The request body.

Content-Type: application/json
tool_resources OpenAI.ModifyThreadRequestToolResources | null
code_interpreter OpenAI.ModifyThreadRequestToolResourcesCodeInterpreter
file_ids string[]
file_search OpenAI.ModifyThreadRequestToolResourcesFileSearch
vector_store_ids string[]
metadata OpenAI.Metadata | null

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

[key: string] string

响应

The request has succeeded.

正文

Content-Type: application/json
id string 必需

The identifier, which can be referenced in API endpoints.

object enum 必需

The object type, which is always thread.

thread
created_at integer 必需

The Unix timestamp (in seconds) for when the thread was created.

tool_resources OpenAI.ThreadObjectToolResources | null 必需
code_interpreter OpenAI.ThreadObjectToolResourcesCodeInterpreter
file_ids string[]
file_search OpenAI.ThreadObjectToolResourcesFileSearch
vector_store_ids string[]
metadata OpenAI.Metadata | null 必需

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard. Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters.

[key: string] string

Client error

正文

Content-Type: application/json
error OpenAI.Error 必需
code string | null 必需
message string 必需
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
以下任何项:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string 必需

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

正文

Content-Type: application/json
error OpenAI.Error 必需
code string | null 必需
message string 必需
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
以下任何项:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string 必需

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

请求

curl https://api.openai.com/v1/threads/thread_abc123 \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
      "metadata": {
        "modified": "true",
        "user": "abc123"
      }
    }'
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
thread = client.beta.threads.update(
    thread_id="thread_id",
)
print(thread.id)
import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const updatedThread = await openai.beta.threads.update(
    "thread_abc123",
    {
      metadata: { modified: "true", user: "abc123" },
    }
  );

  console.log(updatedThread);
}

main();
import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});

const thread = await client.beta.threads.update('thread_id');

console.log(thread.id);
package main

import (
    "context"
    "fmt"

    "github.com/openai/openai-go"
    "github.com/openai/openai-go/option"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    thread, err := client.Beta.Threads.Update(
        context.TODO(),
        "thread_id",
        openai.BetaThreadUpdateParams{},
    )
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", thread.ID)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.threads.Thread;
import com.openai.models.beta.threads.ThreadUpdateParams;

public final class Main {
    private Main() {}

    public static void main(String[] args) {
        OpenAIClient client = OpenAIOkHttpClient.fromEnv();

        Thread thread = client.beta().threads().update("thread_id");
    }
}
require "openai"

openai = OpenAI::Client.new(api_key: "My API Key")

thread = openai.beta.threads.update("thread_id")

puts(thread)

响应

{
  "id": "thread_abc123",
  "object": "thread",
  "created_at": 1699014083,
  "metadata": {
    "modified": "true",
    "user": "abc123"
  },
  "tool_resources": {}
}
zh-cn
你的隐私选择
  • AI 免责声明
  • 早期版本
  • 博客
  • 参与
  • 隐私
  • 消费者健康隐私
  • 使用条款
  • 商标
  • © Microsoft 2026