Conversations
Create conversation items
Adds one or more items to the specified conversation.
Parámetros de la ruta de acceso
conversation_id
string
requerido
The id of the conversation on which the item needs to be created.
Parámetros de consulta
include
string[]
Additional fields to include in the response.
See the include parameter for listing Conversation items for more information.
Parámetros de encabezado
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.
Cuerpo de la solicitud
items
OpenAI.Item[]
requerido
The items to add to the conversation. You may add up to 20 items at a time.
Respuestas
The request has succeeded.
Cuerpo
object
enum
requerido
The type of object returned, must be list.
data
OpenAI.ConversationItem[]
requerido
A list of conversation items.
has_more
boolean
requerido
Whether there are more items available.
first_id
string
requerido
The ID of the first item in the list.
last_id
string
requerido
The ID of the last item in the list.
Solicitar
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)
Respuesta
{
"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
}