Ana içeriğe atla

Bu tarayıcı artık desteklenmiyor.

En son özelliklerden, güvenlik güncelleştirmelerinden ve teknik destekten faydalanmak için Microsoft Edge’e yükseltin.

Microsoft Edge'i indirin Internet Explorer ve Microsoft Edge hakkında daha fazla bilgi
microsoft-foundry.rest.security.o-auth2-auth

Threads, Assistants

Create a message

POST /openai/v1/threads/{thread_id}/messages

Creates a message from the supplied request.

Yol parametreleri

thread_id string gerekli

The ID of the thread to create a message for.

İstek Gövdesi

The request body.

Content-Type: application/json
role enum gerekli

The role of the entity that is creating the message. Allowed values include: - user: Indicates the message is sent by an actual user and should be used in most cases to represent user-generated messages. - assistant: Indicates the message is generated by the assistant. Use this value to insert messages from the assistant into the conversation.

userassistant
content string | (OpenAI.MessageContentImageFileObject | OpenAI.MessageContentImageUrlObject | OpenAI.MessageRequestContentTextObject)[] gerekli
Aşağıdakilerden biri:
string
(OpenAI.MessageContentImageFileObject | OpenAI.MessageContentImageUrlObject | OpenAI.MessageRequestContentTextObject)[]
attachments OpenAI.CreateMessageRequestAttachments[] | null
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

Yanıtlar

The request has succeeded.

Gövde

Content-Type: application/json
id string gerekli

The identifier, which can be referenced in API endpoints.

object enum gerekli

The object type, which is always thread.message.

thread.message
created_at integer gerekli

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

thread_id string gerekli

The thread ID that this message belongs to.

status enum gerekli

The status of the message, which can be either in_progress, incomplete, or completed.

in_progressincompletecompleted
incomplete_details OpenAI.MessageObjectIncompleteDetails | null gerekli
reason enum gerekli
content_filtermax_tokensrun_cancelledrun_expiredrun_failed
completed_at integer | null gerekli
incomplete_at integer | null gerekli
role enum gerekli

The entity that produced the message. One of user or assistant.

userassistant
content OpenAI.MessageObjectContent[] gerekli

The content of the message in array of text and/or images.

assistant_id string | null gerekli
run_id string | null gerekli
attachments OpenAI.MessageObjectAttachments[] | null gerekli
metadata OpenAI.Metadata | null gerekli

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

Gövde

Content-Type: application/json
error OpenAI.Error gerekli
code string | null gerekli
message string gerekli
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Aşağıdakilerden biri:
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 gerekli

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Gövde

Content-Type: application/json
error OpenAI.Error gerekli
code string | null gerekli
message string gerekli
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Aşağıdakilerden biri:
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 gerekli

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

İstek

curl https://api.openai.com/v1/threads/thread_abc123/messages \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "OpenAI-Beta: assistants=v2" \
  -d '{
      "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
)
message = client.beta.threads.messages.create(
    thread_id="thread_id",
    content="string",
    role="user",
)
print(message.id)
import OpenAI from "openai";

const openai = new OpenAI();

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

  console.log(threadMessages);
}

main();
import OpenAI from 'openai';

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

const message = await client.beta.threads.messages.create('thread_id', {
  content: 'string',
  role: 'user',
});

console.log(message.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"),
    )
    message, err := client.Beta.Threads.Messages.New(
        context.TODO(),
        "thread_id",
        openai.BetaThreadMessageNewParams{
            Content: openai.BetaThreadMessageNewParamsContentUnion{
                OfString: openai.String("string"),
            },
            Role: openai.BetaThreadMessageNewParamsRoleUser,
        },
    )
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", message.ID)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.beta.threads.messages.Message;
import com.openai.models.beta.threads.messages.MessageCreateParams;

public final class Main {
    private Main() {}

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

        MessageCreateParams params = MessageCreateParams.builder()
            .threadId("thread_id")
            .content("string")
            .role(MessageCreateParams.Role.USER)
            .build();
        Message message = client.beta().threads().messages().create(params);
    }
}
require "openai"

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

message = openai.beta.threads.messages.create("thread_id", content: "string", role: :user)

puts(message)

Response

{
  "id": "msg_abc123",
  "object": "thread.message",
  "created_at": 1713226573,
  "assistant_id": null,
  "thread_id": "thread_abc123",
  "run_id": null,
  "role": "user",
  "content": [
    {
      "type": "text",
      "text": {
        "value": "How does AI work? Explain it in simple terms.",
        "annotations": []
      }
    }
  ],
  "attachments": [],
  "metadata": {}
}
tr-tr
Gizlilik Tercihleriniz
  • AI Bildirim
  • Önceki Sürümler
  • Blog
  • Katkıda Bulunun
  • Gizlilik
  • Tüketici Sağlığı Gizliliği
  • Kullanım Koşulları
  • Ticari Markalar
  • © Microsoft 2026