microsoft-foundry.rest.security.o-auth2-auth
Chat
Get chat completion messages
GET
/openai/v1/chat/completions/{completion_id}/messages
Retrieves chat completion messages by its identifier.
路径参数
completion_id
string
必需
The ID of the chat completion to retrieve messages from.
查询参数
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.
ascdesc
响应
The request has succeeded.
正文
Content-Type: application/json
object
enum
必需
The type of this object. It is always set to "list".
list
data
OpenAI.ChatCompletionMessageListData[]
必需
An array of chat completion message objects.
first_id
string | null
必需
The identifier of the first chat message in the data array.
last_id
string | null
必需
The identifier of the last chat message in the data array.
has_more
boolean
必需
Indicates whether there are more chat messages available.
请求
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)
响应
{
"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
}