Skip to content

Create Chat Completion

client.chat.completions.create(params)
POST/v1/chat/completions

Create an OpenAI-compatible chat completion with any supported SandBase chat model. Provider-compatible fields are preserved when supported by the selected route.

Request body

ChatCompletionCreateParams
stringmodelrequired

Model identifier from the Models API.

object[]messagesrequired

Conversation messages using roles supported by the selected provider, commonly system, developer, user, assistant, or tool.

Optional<number>temperature

Sampling temperature from 0 to 2.

Default: 1

Optional<number>top_p

Nucleus sampling threshold.

Default: 1

Optional<integer>max_tokens

Maximum number of output tokens.

Optional<boolean>stream

Return incremental Server-Sent Events.

Default: false

Optional<string | string[]>stop

Sequence or sequences that stop generation.

Optional<object[]>tools

Function definitions available to the model.

Optional<string | object>tool_choice

Controls whether and which tool is selected.

Default: auto

Optional<boolean>parallel_tool_calls

Allow supported models to emit multiple tool calls in one turn.

Optional<string>user

Provider-compatible end-user identifier.

Optional<object>response_format

JSON object or JSON Schema output configuration.

Optional<string>reasoning_effort

Provider-compatible reasoning effort setting.

Optional<object>reasoning

Reasoning configuration such as effort or max_tokens.

Optional<object>thinking

Thinking configuration such as type or budget_tokens.

Optional<object>extra_body

Provider-specific parameters for routes that require protocol translation.

Optional<integer>n

Number of completion choices to generate.

Default: 1

Optional<number>presence_penalty

Presence penalty from -2 to 2.

Default: 0

Optional<number>frequency_penalty

Frequency penalty from -2 to 2.

Default: 0

Optional<object>stream_options

Streaming options such as include_usage.

Streaming and tools

Set stream to true for SSE; the stream ends with data: [DONE]. Add stream_options.include_usage for the final usage chunk. Tool calls and multimodal content follow the OpenAI-compatible schema.

Provider compatibility

SandBase preserves additional compatible fields on same-protocol routes. Cross-protocol and provider-specific field support varies; use extra_body where applicable.

Errors

400

Invalid request body or unsupported parameter.

401

Missing or invalid API key.

402

Organization spending limit reached.

404

Model not found or unavailable.

429

Rate limit exceeded.

500

Request persistence or organization lookup failed.

502

The selected provider returned an invalid response.

503

No provider route succeeded.