Chat
Get chat completion messages
Retrieves chat completion messages by its identifier.
Pfadparameter
completion_id
string
Erforderlich
The ID of the chat completion to retrieve messages from.
Abfrageparameter
after
string
Identifier for the last message from the previous pagination request.
limit
integer
Number of messages to retrieve.
order
enum
Sort order for messages by timestamp. Use asc for ascending order or desc for descending order. Defaults to asc.
Antworten
The request has succeeded.
Text
object
enum
Erforderlich
The type of this object. It is always set to "list".
data
OpenAI.ChatCompletionMessageListData[]
Erforderlich
An array of chat completion message objects.
first_id
string | null
Erforderlich
The identifier of the first chat message in the data array.
last_id
string | null
Erforderlich
The identifier of the last chat message in the data array.
has_more
boolean
Erforderlich
Indicates whether there are more chat messages available.
Anfordern
curl https://api.openai.com/v1/chat/completions/chat_abc123/messages \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json"
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
)
page = client.chat.completions.messages.list(
completion_id="completion_id",
)
page = page.data[0]
print(page)
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env['OPENAI_API_KEY'], // This is the default and can be omitted
});
// Automatically fetches more pages as needed.
for await (const chatCompletionStoreMessage of client.chat.completions.messages.list(
'completion_id',
)) {
console.log(chatCompletionStoreMessage);
}
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"),
)
page, err := client.Chat.Completions.Messages.List(
context.TODO(),
"completion_id",
openai.ChatCompletionMessageListParams{},
)
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v
", page)
}
package com.openai.example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.chat.completions.messages.MessageListPage;
import com.openai.models.chat.completions.messages.MessageListParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
MessageListPage page = client.chat().completions().messages().list("completion_id");
}
}
require "openai"
openai = OpenAI::Client.new(api_key: "My API Key")
page = openai.chat.completions.messages.list("completion_id")
puts(page)
Antwort
{
"object": "list",
"data": [
{
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"role": "user",
"content": "write a haiku about ai",
"name": null,
"content_parts": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2-0",
"has_more": false
}