Chat - Python SDK

Chat method reference

The Python SDK and docs are currently in beta. Report issues on GitHub.

(chat)

Overview

Available Operations

  • send - Create a chat completion

send

Sends a request for a model response for the given chat conversation. Supports both streaming and non-streaming modes.

Example Usage

Parameters

ParameterTypeRequiredDescription
messagesList[components.Message]✔️N/A
providerOptionalNullable[components.ChatGenerationParamsProvider]When multiple model providers are available, optionally indicate your routing preference.
pluginsList[components.ChatGenerationParamsPluginUnion]Plugins you want to enable for this request, including their settings.
routeOptionalNullable[components.Route]N/A
userOptional[str]N/A
session_idOptional[str]A unique identifier for grouping related requests (e.g., a conversation or agent workflow) for observability. If provided in both the request body and the x-session-id header, the body value takes precedence. Maximum of 128 characters.
modelOptional[str]N/A
modelsList[str]N/A
frequency_penaltyOptionalNullable[float]N/A
logit_biasDict[str, float]N/A
logprobsOptionalNullable[bool]N/A
top_logprobsOptionalNullable[float]N/A
max_completion_tokensOptionalNullable[float]N/A
max_tokensOptionalNullable[float]N/A
metadataDict[str, str]N/A
presence_penaltyOptionalNullable[float]N/A
reasoningOptional[components.Reasoning]N/A
response_formatOptional[components.ResponseFormat]N/A
seedOptionalNullable[int]N/A
stopOptionalNullable[components.Stop]N/A
streamOptional[bool]N/A
stream_optionsOptionalNullable[components.ChatStreamOptions]N/A
temperatureOptionalNullable[float]N/A
tool_choiceOptional[Any]N/A
toolsList[components.ToolDefinitionJSON]N/A
top_pOptionalNullable[float]N/A
debugOptional[components.Debug]N/A
image_configDict[str, components.ChatGenerationParamsImageConfig]N/A
modalitiesList[components.Modality]N/A
retriesOptional[utils.RetryConfig]Configuration to override the default retry behavior of the client.

Response

operations.SendChatCompletionRequestResponse

Errors

Error TypeStatus CodeContent Type
errors.ChatError400, 401, 429application/json
errors.ChatError500application/json
errors.OpenRouterDefaultError4XX, 5XX*/*