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.

Request body

ChatCompletionCreateParams
stringmodelrequired

Model identifier from the Models API.

object[]messagesrequired

Conversation messages in system, user, assistant, or tool order.

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<object>response_format

JSON object or JSON Schema output configuration.

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<string>user

Stable end-user identifier for abuse monitoring.

Optional<object>stream_options

Streaming options such as include_usage.

Streaming and tools

Set stream to true for SSE. Tool calls and multimodal content follow the OpenAI-compatible schema; detailed workflows live in the Chat Completions guide.

Model support

Optional capabilities depend on the selected model. Inspect model metadata before using tools, vision, or strict structured output.

Errors

400

Invalid request body or unsupported parameter.

401

Missing or invalid API key.

404

Model not found or unavailable.

429

Rate limit exceeded.