Lompati ke konten utama

Browser ini sudah tidak didukung.

Tingkatkan ke Microsoft Edge untuk memanfaatkan fitur, pembaruan keamanan, dan dukungan teknis terkini.

Unduh Microsoft Edge Informasi selengkapnya tentang Internet Explorer dan Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Conversations

Create conversation items

POST /openai/v1/conversations/{conversation_id}/items

Adds one or more items to the specified conversation.

Parameter jalur

conversation_id string diperlukan

The id of the conversation on which the item needs to be created.

Parameter kueri

include string[]

Additional fields to include in the response. See the include parameter for listing Conversation items for more information.

Parameter header

x-ms-user-identity string

Opaque per-user identity string used to scope endpoint-scoped data to a specific end user. The caller must have the agents/endpoints/UserIdentityImpersonation/action RBAC permission.

Isi Permintaan

Content-Type: application/json
items OpenAI.Item[] diperlukan

The items to add to the conversation. You may add up to 20 items at a time.

Respons

The request has succeeded.

Isi

Content-Type: application/json
object enum diperlukan

The type of object returned, must be list.

list
data OpenAI.ConversationItem[] diperlukan

A list of conversation items.

has_more boolean diperlukan

Whether there are more items available.

first_id string diperlukan

The ID of the first item in the list.

last_id string diperlukan

The ID of the last item in the list.

Client error

Isi

Content-Type: application/json
error OpenAI.Error diperlukan
code string | null diperlukan
message string diperlukan
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Salah satu dari yang berikut:
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 diperlukan

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Isi

Content-Type: application/json
error OpenAI.Error diperlukan
code string | null diperlukan
message string diperlukan
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Salah satu dari yang berikut:
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 diperlukan

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Minta

curl https://api.openai.com/v1/conversations/conv_123/items \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "items": [
      {
        "type": "message",
        "role": "user",
        "content": [
          {"type": "input_text", "text": "Hello!"}
        ]
      },
      {
        "type": "message",
        "role": "user",
        "content": [
          {"type": "input_text", "text": "How are you?"}
        ]
      }
    ]
  }'
import OpenAI from "openai";
const client = new OpenAI();

const items = await client.conversations.items.create(
  "conv_123",
  {
    items: [
      {
        type: "message",
        role: "user",
        content: [{ type: "input_text", text: "Hello!" }],
      },
      {
        type: "message",
        role: "user",
        content: [{ type: "input_text", text: "How are you?" }],
      },
    ],
  }
);
console.log(items.data);
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
conversation_item_list = client.conversations.items.create(
    conversation_id="conv_123",
    items=[{
        "content": "string",
        "role": "user",
        "type": "message",
    }],
)
print(conversation_item_list.first_id)
using System;
using System.Collections.Generic;
using OpenAI.Conversations;

OpenAIConversationClient client = new(
    apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")
);

ConversationItemList created = client.ConversationItems.Create(
    conversationId: "conv_123",
    new CreateConversationItemsOptions
    {
        Items = new List<ConversationItem>
        {
            new ConversationMessage
            {
                Role = "user",
                Content =
                {
                    new ConversationInputText { Text = "Hello!" }
                }
            },
            new ConversationMessage
            {
                Role = "user",
                Content =
                {
                    new ConversationInputText { Text = "How are you?" }
                }
            }
        }
    }
);
Console.WriteLine(created.Data.Count);
import OpenAI from 'openai';

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

const conversationItemList = await client.conversations.items.create('conv_123', {
  items: [
    {
      content: 'string',
      role: 'user',
      type: 'message',
    },
  ],
});

console.log(conversationItemList.first_id);
package main

import (
    "context"
    "fmt"

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

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    conversationItemList, err := client.Conversations.Items.New(
        context.TODO(),
        "conv_123",
        conversations.ItemNewParams{
            Items: []responses.ResponseInputItemUnionParam{{
                OfMessage: &responses.EasyInputMessageParam{
                    Content: responses.EasyInputMessageContentUnionParam{
                        OfString: openai.String("string"),
                    },
                    Role: responses.EasyInputMessageRoleUser,
                    Type: responses.EasyInputMessageTypeMessage,
                },
            }},
        },
    )
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", conversationItemList.FirstID)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.conversations.items.ConversationItemList;
import com.openai.models.conversations.items.ItemCreateParams;
import com.openai.models.responses.EasyInputMessage;

public final class Main {
    private Main() {}

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

        ItemCreateParams params = ItemCreateParams.builder()
            .conversationId("conv_123")
            .addItem(EasyInputMessage.builder()
                .content("string")
                .role(EasyInputMessage.Role.USER)
                .type(EasyInputMessage.Type.MESSAGE)
                .build())
            .build();
        ConversationItemList conversationItemList = client.conversations().items().create(params);
    }
}
require "openai"

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

conversation_item_list = openai.conversations.items.create("conv_123", items: [{content: "string", role: :user, type: :message}])

puts(conversation_item_list)

Tanggapan

{
  "object": "list",
  "data": [
    {
      "type": "message",
      "id": "msg_abc",
      "status": "completed",
      "role": "user",
      "content": [
        {"type": "input_text", "text": "Hello!"}
      ]
    },
    {
      "type": "message",
      "id": "msg_def",
      "status": "completed",
      "role": "user",
      "content": [
        {"type": "input_text", "text": "How are you?"}
      ]
    }
  ],
  "first_id": "msg_abc",
  "last_id": "msg_def",
  "has_more": false
}
id-id
Pilihan Privasi Anda
  • Pengelakan AI
  • Versi Sebelumnya
  • Blog
  • Berikan kontribusi
  • Privasi
  • Privasi Kesehatan Konsumen
  • Persyaratan Penggunaan
  • Merek Dagang
  • © Microsoft 2026