NAME

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

DESCRIPTION

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

PATHS

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

    Allowed values: asc, desc

    Default: asc

Responses

Status Code: 200

A list of Chat Completions

Content Types:

  • application/json

    Example (See the OpenAI spec for more detail):

    {
      "object": "list",
      "data": [
        {
          "object": "chat.completion",
          "id": "chatcmpl-AyPNinnUqUDYo9SAdA52NobMflmj2",
          "model": "gpt-4o-2024-08-06",
          "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,  \nLearning patterns in silence—  \nFuture'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
    }

POST /chat/completions

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.

Operation ID

createChatCompletion

$client->createChatCompletion( ... );

Parameters

Request Body

Content Type: application/json

Responses

Status Code: 200

OK

Content Types:

  • application/json

    Example (See the OpenAI spec for more detail):

    {
      "id": "chatcmpl-B9MHDbslfkBeAs8l4bebGdFOJ6PeG",
      "object": "chat.completion",
      "created": 1741570283,
      "model": "gpt-4o-2024-08-06",
      "choices": [
        {
          "index": 0,
          "message": {
            "role": "assistant",
            "content": "The image shows a wooden boardwalk path running through a lush green field or meadow. The sky is bright blue with some scattered clouds, giving the scene a serene and peaceful atmosphere. Trees and shrubs are visible in the background.",
            "refusal": null,
            "annotations": []
          },
          "logprobs": null,
          "finish_reason": "stop"
        }
      ],
      "usage": {
        "prompt_tokens": 1117,
        "completion_tokens": 46,
        "total_tokens": 1163,
        "prompt_tokens_details": {
          "cached_tokens": 0,
          "audio_tokens": 0
        },
        "completion_tokens_details": {
          "reasoning_tokens": 0,
          "audio_tokens": 0,
          "accepted_prediction_tokens": 0,
          "rejected_prediction_tokens": 0
        }
      },
      "service_tier": "default",
      "system_fingerprint": "fp_fc9f1d7035"
    }
  • text/event-stream

    Example (See the OpenAI spec for more detail):

    {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"role":"assistant","content":""},"logprobs":null,"finish_reason":null}]}
    
    {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{"content":"Hello"},"logprobs":null,"finish_reason":null}]}
    
    ....
    
    {"id":"chatcmpl-123","object":"chat.completion.chunk","created":1694268190,"model":"gpt-4o-mini", "system_fingerprint": "fp_44709d6fcb", "choices":[{"index":0,"delta":{},"logprobs":null,"finish_reason":"stop"}]}

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.