Chat
List chat completions
Lists chat completions matching the request filters.
Query parameters
model
string
The model used to generate the Chat Completions.
metadata
OpenAI.Metadata | null
A list of metadata keys to filter the Chat Completions by. Example:
metadata[key1]=value1&metadata[key2]=value2
after
string
Identifier for the last chat completion from the previous pagination request.
limit
integer
Number of Chat Completions to retrieve.
order
enum
Sort order for Chat Completions by timestamp. Use asc for ascending order or desc for descending order. Defaults to asc.
Responses
The request has succeeded.
Body
object
enum
required
The type of this object. It is always set to "list".
data
OpenAI.CreateChatCompletionResponse[]
required
An array of chat completion objects.
first_id
string | null
required
The identifier of the first chat completion in the data array.
last_id
string | null
required
The identifier of the last chat completion in the data array.
has_more
boolean
required
Indicates whether there are more Chat Completions available.
Request
curl https://api.openai.com/v1/chat/completions \
-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.list()
page = page.data[0]
print(page.id)
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 chatCompletion of client.chat.completions.list()) {
console.log(chatCompletion.id);
}
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.List(context.TODO(), openai.ChatCompletionListParams{})
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.ChatCompletionListPage;
import com.openai.models.chat.completions.ChatCompletionListParams;
public final class Main {
private Main() {}
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
ChatCompletionListPage page = client.chat().completions().list();
}
}
require "openai"
openai = OpenAI::Client.new(api_key: "My API Key")
page = openai.chat.completions.list
puts(page)
Response
{
"object": "list",
"data": [
{
"object": "chat.completion",
"id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"model": "gpt-5.4",
"created": 1738960610,
"request_id": "req_ded8ab984ec4bf840f37566c1011c417",
"tool_choice": null,
"usage": {
"total_tokens": 31,
"completion_tokens": 18,
"prompt_tokens": 13
},
"seed": 4944116822809979520,
"top_p": 1.0,
"temperature": 1.0,
"presence_penalty": 0.0,
"frequency_penalty": 0.0,
"system_fingerprint": "fp_50cad350e4",
"input_user": null,
"service_tier": "default",
"tools": null,
"metadata": {},
"choices": [
{
"index": 0,
"message": {
"content": "Mind of circuits hum,
Learning patterns in silence—
Future's quiet spark.",
"role": "assistant",
"tool_calls": null,
"function_call": null
},
"finish_reason": "stop",
"logprobs": null
}
],
"response_format": null
}
],
"first_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"last_id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"has_more": false
}