mirror of
https://github.com/wassname/openrouter-python-sdk-retry-errors.git
synced 2026-07-29 11:23:49 +08:00
Updates include: - Updated OpenAPI spec with new component schemas - Restructured component documentation with nested parameter types - Added new components for plugin and provider configurations - Updated chat generation params and response request structures - Version bump and dependency updates
29 KiB
29 KiB
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[components.Message] | ✔️ | N/A |
provider |
OptionalNullable[components.ChatGenerationParamsProvider] | ➖ | When multiple model providers are available, optionally indicate your routing preference. |
plugins |
List[components.ChatGenerationParamsPluginUnion] | ➖ | Plugins you want to enable for this request, including their settings. |
route |
OptionalNullable[components.ChatGenerationParamsRoute] | ➖ | Routing strategy for multiple models: "fallback" (default) uses secondary models as backups, "sort" sorts all endpoints together by routing criteria. |
user |
Optional[str] | ➖ | N/A |
session_id |
Optional[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. |
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[components.Reasoning] | ➖ | N/A |
response_format |
Optional[components.ChatGenerationParamsResponseFormatUnion] | ➖ | N/A |
seed |
OptionalNullable[int] | ➖ | N/A |
stop |
OptionalNullable[components.ChatGenerationParamsStop] | ➖ | N/A |
stream |
Optional[bool] | ➖ | N/A |
stream_options |
OptionalNullable[components.ChatStreamOptions] | ➖ | N/A |
temperature |
OptionalNullable[float] | ➖ | N/A |
tool_choice |
Optional[Any] | ➖ | N/A |
tools |
List[components.ToolDefinitionJSON] | ➖ | N/A |
top_p |
OptionalNullable[float] | ➖ | N/A |
debug |
Optional[components.Debug] | ➖ | N/A |
retries |
Optional[utils.RetryConfig] | ➖ | Configuration to override the default retry behavior of the client. |
Response
operations.SendChatCompletionRequestResponse
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.ChatError | 400, 401, 429 | application/json |
| errors.ChatError | 500 | application/json |
| errors.OpenRouterDefaultError | 4XX, 5XX | */* |