NAME

OpenAPI::Client::OpenAI::Path::chat-completions - Documentation for the /chat/completions path.

DESCRIPTION

This document describes the API endpoint at /chat/completions.

See the examples/ directory in the distribution for examples of how to use this.

GET /chat/completions

List stored Chat Completions. Only Chat Completions that have been stored with the `store` parameter set to `true` will be returned.

Operation ID

listChatCompletions

$client->listChatCompletions( ... );

Parameters

  • model (in query) (Optional) - The model used to generate the Chat Completions. Type: string

  • metadata (in query) (Optional) - A list of metadata keys to filter the Chat Completions by. Example:

    `metadata[key1]=value1&metadata[key2]=value2`

    Type: object

  • after (in query) (Optional) - Identifier for the last chat completion from the previous pagination request. Type: string

  • limit (in query) (Optional) - Number of Chat Completions to retrieve. Type: integer

    Default: 20

  • order (in query) (Optional) - Sort order for Chat Completions by timestamp. Use `asc` for ascending order or `desc` for descending order. Defaults to `asc`. Type: string

    Possible values: asc desc

    Default: asc

Responses

Status Code: 200

A list of Chat Completions

Content Types:

  • application/json

    Example:

    {
       "data" : [
          {
             "service_tier" : "scale",
             "usage" : {
                "completion_tokens_details" : null,
                "prompt_tokens_details" : null
             },
             "choices" : [
                {
                   "message" : {
                      "tool_calls" : [
                         {
                            "function" : null
                         }
                      ],
                      "audio" : null,
                      "function_call" : null,
                      "annotations" : [
                         {
                            "url_citation" : null
                         }
                      ]
                   },
                   "logprobs" : {
                      "content" : [
                         {
                            "top_logprobs" : [
                               {
                                  "bytes" : [
                                     null
                                  ]
                               }
                            ],
                            "bytes" : [
                               null
                            ]
                         }
                      ],
                      "refusal" : [
                         {
                            "bytes" : [
                               null
                            ],
                            "top_logprobs" : [
                               {
                                  "bytes" : [
                                     null
                                  ]
                               }
                            ]
                         }
                      ]
                   }
                }
             ]
          }
       ]
    }

POST /chat/completions

**Starting a new project?** We recommend trying [Responses](/docs/api-reference/responses) to take advantage of the latest OpenAI platform features. Compare [Chat Completions with Responses](/docs/guides/responses-vs-chat-completions?api-mode=responses).

---

Creates a model response for the given chat conversation. Learn more in the [text generation](/docs/guides/text-generation), [vision](/docs/guides/vision), and [audio](/docs/guides/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](/docs/guides/reasoning).

Operation ID

createChatCompletion

$client->createChatCompletion( ... );

Request Body

Content Type: application/json

Responses

Status Code: 200

OK

Content Types:

  • application/json

    Example:

    {
       "service_tier" : "scale",
       "choices" : [
          {
             "logprobs" : {
                "content" : [
                   {
                      "top_logprobs" : [
                         {
                            "bytes" : [
                               null
                            ]
                         }
                      ],
                      "bytes" : [
                         null
                      ]
                   }
                ],
                "refusal" : [
                   {
                      "top_logprobs" : [
                         {
                            "bytes" : [
                               null
                            ]
                         }
                      ],
                      "bytes" : [
                         null
                      ]
                   }
                ]
             },
             "message" : {
                "tool_calls" : [
                   {
                      "function" : null
                   }
                ],
                "audio" : null,
                "function_call" : null,
                "annotations" : [
                   {
                      "url_citation" : null
                   }
                ]
             }
          }
       ],
       "usage" : {
          "prompt_tokens_details" : null,
          "completion_tokens_details" : null
       }
    }
  • text/event-stream

    Example:

    {
       "choices" : [
          {
             "delta" : {
                "tool_calls" : [
                   {
                      "function" : null
                   }
                ],
                "function_call" : null
             },
             "logprobs" : {
                "refusal" : [
                   {
                      "bytes" : [
                         null
                      ],
                      "top_logprobs" : [
                         {
                            "bytes" : [
                               null
                            ]
                         }
                      ]
                   }
                ],
                "content" : [
                   {
                      "top_logprobs" : [
                         {
                            "bytes" : [
                               null
                            ]
                         }
                      ],
                      "bytes" : [
                         null
                      ]
                   }
                ]
             }
          }
       ],
       "usage" : {
          "prompt_tokens_details" : null,
          "completion_tokens_details" : null
       },
       "service_tier" : "scale"
    }

SEE ALSO

OpenAPI::Client::OpenAI::Path

COPYRIGHT AND LICENSE

Copyright (C) 2023-2025 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.