NAME
OpenAPI::Client::OpenAI::Path::chat-completions - Documentation for the /chat/completions path.
OPERATIONS
GET /chat/completions
listChatCompletions
$client->list_chat_completions({
body => { ... },
});
List stored Chat Completions. Only Chat Completions that have been stored with the store parameter set to true will be returned.
Path/query parameters
model(in query, optional, string) - The model used to generate the Chat Completions.metadata(in query, optional, string) - A list of metadata keys to filter the Chat Completions by. Example:metadata[key1]=value1&metadata[key2]=value2after(in query, optional, string) - Identifier for the last chat completion from the previous pagination request.limit(in query, optional, integer) - Number of Chat Completions to retrieve.Default: 20
order(in query, optional, string) - Sort order for Chat Completions by timestamp. Useascfor ascending order ordescfor descending order. Defaults toasc.Allowed values: asc, desc
Default: asc
Responses
200 - A list of Chat Completions
Content-Type: application/json
Example:
{
"data" : [
{
"choices" : [
{
"finish_reason" : "stop",
"index" : 0,
"logprobs" : null,
"message" : {
"content" : "Mind of circuits hum, \nLearning patterns in silence— \nFuture's quiet spark.",
"function_call" : null,
"role" : "assistant",
"tool_calls" : null
}
}
],
"created" : 1738960610,
"frequency_penalty" : 0,
"id" : "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"input_user" : null,
"metadata" : {},
"model" : "gpt-4o-2024-08-06",
"object" : "chat.completion",
"presence_penalty" : 0,
"request_id" : "req_ded8ab984ec4bf840f37566c1011c417",
"response_format" : null,
"seed" : 4944116822809979520,
"service_tier" : "default",
"system_fingerprint" : "fp_50cad350e4",
"temperature" : 1,
"tool_choice" : null,
"tools" : null,
"top_p" : 1,
"usage" : {
"completion_tokens" : 18,
"prompt_tokens" : 13,
"total_tokens" : 31
}
}
],
"first_id" : "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"has_more" : false,
"last_id" : "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
"object" : "list"
}
POST /chat/completions
createChatCompletion
$client->create_chat_completion({
body => { ... },
});
Starting a new project? We recommend trying Responses to take advantage of the latest OpenAI platform features. Compare Chat Completions with Responses .
Creates a model response for the given chat conversation. Learn more in the text generation , vision , and audio guides.
Parameter support can differ depending on the model used to generate the response, particularly for newer reasoning models. Parameters that are only supported for reasoning models are noted below. For the current state of unsupported parameters in reasoning models, refer to the reasoning guide .
Returns a chat completion object, or a streamed sequence of chat completion chunk objects if the request is streamed.
Request body
Content-Type: application/json
Example:
{
"choices" : [
{
"finish_reason" : "stop",
"index" : 0,
"logprobs" : null,
"message" : {
"annotations" : [],
"content" : "Hello! How can I assist you today?",
"refusal" : null,
"role" : "assistant"
}
}
],
"created" : 1741569952,
"id" : "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
"model" : "gpt-5.4",
"object" : "chat.completion",
"service_tier" : "default",
"usage" : {
"completion_tokens" : 10,
"completion_tokens_details" : {
"accepted_prediction_tokens" : 0,
"audio_tokens" : 0,
"reasoning_tokens" : 0,
"rejected_prediction_tokens" : 0
},
"prompt_tokens" : 19,
"prompt_tokens_details" : {
"audio_tokens" : 0,
"cached_tokens" : 0
},
"total_tokens" : 29
}
}
Responses
200 - OK
Content-Type: application/json
Example:
{
"choices" : [
{
"finish_reason" : "stop",
"index" : 0,
"logprobs" : null,
"message" : {
"annotations" : [],
"content" : "Hello! How can I assist you today?",
"refusal" : null,
"role" : "assistant"
}
}
],
"created" : 1741569952,
"id" : "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
"model" : "gpt-5.4",
"object" : "chat.completion",
"service_tier" : "default",
"usage" : {
"completion_tokens" : 10,
"completion_tokens_details" : {
"accepted_prediction_tokens" : 0,
"audio_tokens" : 0,
"reasoning_tokens" : 0,
"rejected_prediction_tokens" : 0
},
"prompt_tokens" : 19,
"prompt_tokens_details" : {
"audio_tokens" : 0,
"cached_tokens" : 0
},
"total_tokens" : 29
}
}
Content-Type: text/event-stream
Example:
{
"choices" : [
{
"finish_reason" : "stop",
"index" : 0,
"logprobs" : null,
"message" : {
"annotations" : [],
"content" : "Hello! How can I assist you today?",
"refusal" : null,
"role" : "assistant"
}
}
],
"created" : 1741569952,
"id" : "chatcmpl-B9MBs8CjcvOU2jLn4n570S5qMJKcT",
"model" : "gpt-5.4",
"object" : "chat.completion",
"service_tier" : "default",
"usage" : {
"completion_tokens" : 10,
"completion_tokens_details" : {
"accepted_prediction_tokens" : 0,
"audio_tokens" : 0,
"reasoning_tokens" : 0,
"rejected_prediction_tokens" : 0
},
"prompt_tokens" : 19,
"prompt_tokens_details" : {
"audio_tokens" : 0,
"cached_tokens" : 0
},
"total_tokens" : 29
}
}
SCHEMAS
ChatCompletionList
Properties:
data(array of CreateChatCompletionResponse, required) - An array of chat completion objects.first_id(string, required) - The identifier of the first chat completion in the data array.has_more(boolean, required) - Indicates whether there are more Chat Completions available.last_id(string, required) - The identifier of the last chat completion in the data array.object(string, required) - The type of this object. It is always set to "list".Allowed values: list
Default: list
CompletionUsage
Properties:
completion_tokens(integer, required) - Number of tokens in the generated completion.Default: 0
completion_tokens_details(object) - Breakdown of tokens used in a completion.prompt_tokens(integer, required) - Number of tokens in the prompt.Default: 0
prompt_tokens_details(object) - Breakdown of tokens used in the prompt.total_tokens(integer, required) - Total number of tokens used in the request (prompt + completion).Default: 0
CreateChatCompletionRequest
See https://platform.openai.com/docs/api-reference for details.
CreateChatCompletionResponse
Properties:
choices(array of object, required) - A list of chat completion choices. Can be more than one ifnis greater than 1.created(integer, required) - The Unix timestamp (in seconds) of when the chat completion was created.id(string, required) - A unique identifier for the chat completion.model(string, required) - The model used for the chat completion.object(string, required) - The object type, which is alwayschat.completion.Allowed values: chat.completion
service_tier(ServiceTier)See "ServiceTier" below for shape.
system_fingerprint(string) - This fingerprint represents the backend configuration that the model runs with.Can be used in conjunction with the
seedrequest parameter to understand when backend changes have been made that might impact determinism.usage(CompletionUsage)See "CompletionUsage" below for shape.
CreateChatCompletionStreamResponse
Properties:
choices(array of object, required) - A list of chat completion choices. Can contain more than one elements ifnis greater than 1. Can also be empty for the last chunk if you setstream_options: {"include_usage": true}.created(integer, required) - The Unix timestamp (in seconds) of when the chat completion was created. Each chunk has the same timestamp.id(string, required) - A unique identifier for the chat completion. Each chunk has the same ID.model(string, required) - The model to generate the completion.object(string, required) - The object type, which is alwayschat.completion.chunk.Allowed values: chat.completion.chunk
service_tier(ServiceTier)See "ServiceTier" below for shape.
system_fingerprint(string) - This fingerprint represents the backend configuration that the model runs with. Can be used in conjunction with theseedrequest parameter to understand when backend changes have been made that might impact determinism.usage(CompletionUsage) - An optional field that will only be present when you setstream_options: {"include_usage": true}in your request. When present, it contains a null value except for the last chunk which contains the token usage statistics for the entire request.NOTE: If the stream is interrupted or cancelled, you may not receive the final usage chunk which contains the total token usage for the request.
See "CompletionUsage" below for shape.
ServiceTier
Specifies the processing type used for serving the request. - If set to 'auto', then the request will be processed with the service tier configured in the Project settings. Unless otherwise configured, the Project will use 'default'. - If set to 'default', then the request will be processed with the standard pricing and performance for the selected model. - If set to 'flex' or 'priority', then the request will be processed with the corresponding service tier. - When not set, the default behavior is 'auto'.
When the service_tier parameter is set, the response body will include the service_tier value based on the processing mode actually used to serve the request. This response value may be different from the value set in the parameter.
SEE ALSO
COPYRIGHT AND LICENSE
Copyright (C) 2023-2026 by Nelson Ferraz
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.0 or, at your option, any later version of Perl 5 you may have available.