v1

latestOpenAPI 3.0.3MIT2026-07-132953108.7 KB
Chat Completions

Create Chat Completion

Creates a chat completion using conversational messages. Supports tool calling, image inputs, and multiple AI providers with automatic fallbacks.

post/v1/chat/completions

Request body

modelstring required

Model identifier in 'provider/model' format (e.g., 'openai/gpt-4o-mini', 'anthropic/claude-3-sonnet-20240229')

max_tokensinteger

Maximum number of tokens to generate

fallbacksstring[]

Fallback model names in 'provider/model' format

Example request

{
  "model": "openai/gpt-4o-mini",
  "messages": [
    {
      "role": "user",
      "content": "Hello, how are you?",
      "tool_calls": [
        {
          "id": "tool_123",
          "type": "function",
          "function": {
            "name": "get_weather",
            "arguments": "{\"location\": \"San Francisco, CA\"}"
          }
        }
      ]
    }
  ],
  "max_tokens": 1000,
  "fallbacks": [
    "anthropic/claude-3-sonnet-20240229",
    "openai/gpt-4o"
  ]
}

Response

Successful chat completion

idstring

Unique response identifier

object'chat.completion' | 'text.completion'

Response type

modelstring

Model used for generation

createdinteger

Unix timestamp of creation

service_tierstring

Service tier used

system_fingerprintstring

System fingerprint

Example response

{
  "id": "chatcmpl-123",
  "object": "chat.completion",
  "choices": [
    {
      "message": {
        "role": "user",
        "content": "Hello, how are you?",
        "tool_calls": [
          {
            "id": "tool_123",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\": \"San Francisco, CA\"}"
            }
          }
        ]
      },
      "finish_reason": "stop",
      "log_probs": {
        "content": [
          {
            "logprob": -0.123,
            "token": "hello",
            "top_logprobs": [
              {
                "logprob": -0.456,
                "token": "world"
              }
            ]
          }
        ],
        "refusal": [
          {
            "logprob": -0.456,
            "token": "world"
          }
        ]
      }
    }
  ],
  "model": "gpt-4o",
  "created": 1677652288,
  "usage": {
    "prompt_tokens": 56,
    "completion_tokens": 31,
    "total_tokens": 87
  },
  "extra_fields": {
    "provider": "openai",
    "model_params": {
      "temperature": 0.7,
      "top_p": 0.9,
      "top_k": 40,
      "max_tokens": 1000,
      "stop_sequences": [
        "\n\n",
        "END"
      ],
      "tools": [
        {
          "type": "function",
          "function": {
            "name": "get_weather",
            "description": "Get current weather for a location",
            "parameters": {
              "type": "object"
            }
          }
        }
      ],
      "tool_choice": {
        "type": "auto",
        "function": {
          "name": "get_weather"
        }
      },
      "parallel_tool_calls": true
    },
    "latency": 1.234,
    "chat_history": [
      {
        "role": "user",
        "content": "Hello, how are you?",
        "tool_calls": [
          {
            "id": "tool_123",
            "type": "function",
            "function": {
              "name": "get_weather",
              "arguments": "{\"location\": \"San Francisco, CA\"}"
            }
          }
        ]
      }
    ]
  }
}
All 29 operations