Hoppa till huvudinnehåll

Den här webbläsaren stöds inte längre.

Uppgradera till Microsoft Edge och dra nytta av de senaste funktionerna och säkerhetsuppdateringarna, samt teknisk support.

Ladda ned Microsoft Edge Mer information om Internet Explorer och Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Threads, Assistants

Create a thread

POST /openai/v1/threads

Creates a thread from the supplied request.

Begärandetext

The request body.

Content-Type: application/json
messages OpenAI.CreateMessageRequest[]

A list of messages to start the thread with.

tool_resources OpenAI.CreateThreadRequestToolResources | null
code_interpreter OpenAI.CreateThreadRequestToolResourcesCodeInterpreter
file_ids string[]
file_search OpenAI.CreateThreadRequestToolResourcesFileSearch
vector_store_ids string[]
vector_stores OpenAI.CreateThreadRequestToolResourcesFileSearchVectorStores[]
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

Svar

The request has succeeded.

Brödtext

Content-Type: application/json
id string krävs

The identifier, which can be referenced in API endpoints.

object enum krävs

The object type, which is always thread.

thread
created_at integer krävs

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

tool_resources OpenAI.ThreadObjectToolResources | null krävs
code_interpreter OpenAI.ThreadObjectToolResourcesCodeInterpreter
file_ids string[]
file_search OpenAI.ThreadObjectToolResourcesFileSearch
vector_store_ids string[]
metadata OpenAI.Metadata | null krävs

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

Brödtext

Content-Type: application/json
error OpenAI.Error krävs
code string | null krävs
message string krävs
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Något av följande:
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 krävs

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Brödtext

Content-Type: application/json
error OpenAI.Error krävs
code string | null krävs
message string krävs
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Något av följande:
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 krävs

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Förfrågan

curl https://api.openai.com/v1/threads \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d ''
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.create()
print(thread.id)
import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const emptyThread = await openai.beta.threads.create();

  console.log(emptyThread);
}

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.create();

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.New(context.TODO(), openai.BetaThreadNewParams{})
    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.ThreadCreateParams;

public final class Main {
    private Main() {}

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

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

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

thread = openai.beta.threads.create

puts(thread)

Response

{
  "id": "thread_abc123",
  "object": "thread",
  "created_at": 1699012949,
  "metadata": {},
  "tool_resources": {}
}

Förfrågan

curl https://api.openai.com/v1/threads \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "OpenAI-Beta: assistants=v2" \
-d '{
    "messages": [{
      "role": "user",
      "content": "Hello, what is AI?"
    }, {
      "role": "user",
      "content": "How does AI work? Explain it in simple terms."
    }]
  }'
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.create()
print(thread.id)
import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const messageThread = await openai.beta.threads.create({
    messages: [
      {
        role: "user",
        content: "Hello, what is AI?"
      },
      {
        role: "user",
        content: "How does AI work? Explain it in simple terms.",
      },
    ],
  });

  console.log(messageThread);
}

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.create();

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.New(context.TODO(), openai.BetaThreadNewParams{})
    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.ThreadCreateParams;

public final class Main {
    private Main() {}

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

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

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

thread = openai.beta.threads.create

puts(thread)

Response

{
  "id": "thread_abc123",
  "object": "thread",
  "created_at": 1699014083,
  "metadata": {},
  "tool_resources": {}
}
sv-se
Dina sekretessalternativ
  • Ansvarsfriskrivning för AI
  • Tidigare versioner
  • Blogg
  • Bidra
  • Sekretess
  • Konsumenthälsans integritet
  • Användningsvillkor
  • Varumärken
  • © Microsoft 2026