Files
openrouter-python-sdk-retry…/docs/sdks/chat/README.md
T
Matt Apperson 5fc522c72f Initial commit: OpenRouter Python SDK
Auto-generated Python SDK for OpenRouter API, providing comprehensive client library with:
- Chat completions and streaming support
- Embeddings API
- Model and provider information
- API key management
- Analytics and usage tracking
- OAuth authentication flows
- Full type hints and error handling
2025-11-13 10:56:25 -05:00

13 KiB
Raw Blame History

Chat

(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

from openrouter import OpenRouter
import os


with OpenRouter(
    api_key=os.getenv("OPENROUTER_API_KEY", ""),
) as open_router:

    res = open_router.chat.send(messages=[], stream=False)

    with res as event_stream:
        for event in event_stream:
            # handle event
            print(event, flush=True)

Parameters

Parameter Type Required Description
messages List[models.Message] ✔️ N/A
model Optional[str] N/A
models List[str] N/A
frequency_penalty OptionalNullable[float] N/A
logit_bias Dict[str, float] N/A
logprobs OptionalNullable[bool] N/A
top_logprobs OptionalNullable[float] N/A
max_completion_tokens OptionalNullable[float] N/A
max_tokens OptionalNullable[float] N/A
metadata Dict[str, str] N/A
presence_penalty OptionalNullable[float] N/A
reasoning Optional[models.Reasoning] N/A
response_format Optional[models.ChatGenerationParamsResponseFormatUnion] N/A
seed OptionalNullable[int] N/A
stop OptionalNullable[models.ChatGenerationParamsStop] N/A
stream Optional[bool] N/A
stream_options OptionalNullable[models.ChatStreamOptions] N/A
temperature OptionalNullable[float] N/A
tool_choice Optional[Any] N/A
tools List[models.ToolDefinitionJSON] N/A
top_p OptionalNullable[float] N/A
user Optional[str] N/A
retries Optional[utils.RetryConfig] Configuration to override the default retry behavior of the client.

Response

models.SendChatCompletionRequestResponse

Errors

Error Type Status Code Content Type
errors.ChatError 400, 401, 429 application/json
errors.ChatError 500 application/json
errors.OpenRouterDefaultError 4XX, 5XX */*