Zu Hauptinhalt wechseln

Dieser Browser wird nicht mehr unterstützt.

Führen Sie ein Upgrade auf Microsoft Edge durch, um die neuesten Features, Sicherheitsupdates und den technischen Support zu nutzen.

Microsoft Edge herunterladen Weitere Informationen zu Internet Explorer und 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.

Pfadparameter

conversation_id string Erforderlich

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

Abfrageparameter

include string[]

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

Headerparameter

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.

Anforderungstext

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

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

Antworten

The request has succeeded.

Text

Content-Type: application/json
object enum Erforderlich

The type of object returned, must be list.

list
data OpenAI.ConversationItem[] Erforderlich

A list of conversation items.

has_more boolean Erforderlich

Whether there are more items available.

first_id string Erforderlich

The ID of the first item in the list.

last_id string Erforderlich

The ID of the last item in the list.

Client error

Text

Content-Type: application/json
error OpenAI.Error Erforderlich
code string | null Erforderlich
message string Erforderlich
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Eines der folgenden Elemente:
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 Erforderlich

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Text

Content-Type: application/json
error OpenAI.Error Erforderlich
code string | null Erforderlich
message string Erforderlich
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Eines der folgenden Elemente:
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 Erforderlich

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Anfordern

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)

Antwort

{
  "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
}
de-de
Ihre Datenschutzoptionen
  • KI-Haftungsausschluss
  • Frühere Versionen
  • Blog
  • Mitwirken
  • Datenschutz
  • Consumer Health Privacy
  • Nutzungsbedingungen
  • Impressum
  • Marken
  • © Microsoft 2026