This commit is contained in:
David Alberto Adler
2025-09-07 20:40:53 +01:00
parent 0fc7236673
commit da48e8c4ea
166 changed files with 1689 additions and 4514 deletions
+3 -3
View File
@@ -3,10 +3,10 @@
import importlib.metadata
__title__: str = "openrouter"
__version__: str = "0.1.3"
__version__: str = "0.3.1"
__openapi_doc_version__: str = "1.0.0"
__gen_version__: str = "2.687.1"
__user_agent__: str = "speakeasy-sdk/python 0.1.3 2.687.1 1.0.0 openrouter"
__gen_version__: str = "2.694.1"
__user_agent__: str = "speakeasy-sdk/python 0.3.1 2.694.1 1.0.0 openrouter"
try:
if __package__ is not None:
+11 -1
View File
@@ -15,9 +15,19 @@ from urllib.parse import parse_qs, urlparse
class BaseSDK:
sdk_configuration: SDKConfiguration
parent_ref: Optional[object] = None
"""
Reference to the root SDK instance, if any. This will prevent it from
being garbage collected while there are active streams.
"""
def __init__(self, sdk_config: SDKConfiguration) -> None:
def __init__(
self,
sdk_config: SDKConfiguration,
parent_ref: Optional[object] = None,
) -> None:
self.sdk_configuration = sdk_config
self.parent_ref = parent_ref
def _get_url(self, base_url, url_variables):
sdk_url, sdk_variables = self.sdk_configuration.get_server_details()
+175 -573
View File
@@ -1,6 +1,7 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from .basesdk import BaseSDK
from enum import Enum
from openrouter import errors, models, utils
from openrouter._hooks import HookContext
from openrouter.types import OptionalNullable, UNSET
@@ -8,9 +9,120 @@ from openrouter.utils import eventstreaming, get_security_from_env
from openrouter.utils.unmarshal_json_response import unmarshal_json_response
from typing import Any, Dict, List, Mapping, Optional, Union
# region imports
from typing import overload
from typing_extensions import Literal
# endregion imports
class CompleteAcceptEnum(str, Enum):
APPLICATION_JSON = "application/json"
TEXT_EVENT_STREAM = "text/event-stream"
class Chat(BaseSDK):
r"""Chat completion operations"""
# region sdk-class-body
@overload
def complete(
self,
*,
messages: Union[
List[models.ChatCompletionMessageParam],
List[models.ChatCompletionMessageParamTypedDict],
],
model: Optional[str] = None,
stream: Literal[True],
stream_options: OptionalNullable[
Union[models.StreamOptions, models.StreamOptionsTypedDict]
] = UNSET,
temperature: OptionalNullable[float] = 1,
tool_choice: Optional[
Union[
models.ChatCompletionToolChoiceOption,
models.ChatCompletionToolChoiceOptionTypedDict,
]
] = None,
tools: Optional[
Union[
List[models.ChatCompletionTool],
List[models.ChatCompletionToolTypedDict],
]
] = None,
top_p: OptionalNullable[float] = 1,
user: Optional[str] = None,
model_list: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[models.ReasoningEffort] = UNSET,
provider: OptionalNullable[
Union[models.Provider, models.ProviderTypedDict]
] = UNSET,
plugins: Optional[
Union[List[models.Plugin], List[models.PluginTypedDict]]
] = None,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[CompleteAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> eventstreaming.EventStream[models.ChatCompletionChunkWrapper]: ...
@overload
def complete(
self,
*,
messages: Union[
List[models.ChatCompletionMessageParam],
List[models.ChatCompletionMessageParamTypedDict],
],
model: Optional[str] = None,
frequency_penalty: OptionalNullable[float] = UNSET,
logit_bias: OptionalNullable[Dict[str, float]] = UNSET,
logprobs: OptionalNullable[bool] = UNSET,
top_logprobs: OptionalNullable[float] = UNSET,
max_completion_tokens: OptionalNullable[float] = UNSET,
max_tokens: OptionalNullable[float] = UNSET,
metadata: Optional[Dict[str, str]] = None,
presence_penalty: OptionalNullable[float] = UNSET,
reasoning: OptionalNullable[
Union[models.Reasoning, models.ReasoningTypedDict]
] = UNSET,
response_format: Optional[
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
] = None,
seed: OptionalNullable[int] = UNSET,
stop: OptionalNullable[Union[models.Stop, models.StopTypedDict]] = UNSET,
stream: Union[Literal[False], None] = None,
stream_options: OptionalNullable[
Union[models.StreamOptions, models.StreamOptionsTypedDict]
] = UNSET,
temperature: OptionalNullable[float] = 1,
tool_choice: Optional[
Union[
models.ChatCompletionToolChoiceOption,
models.ChatCompletionToolChoiceOptionTypedDict,
]
] = None,
tools: Optional[
Union[
List[models.ChatCompletionTool],
List[models.ChatCompletionToolTypedDict],
]
] = None,
top_p: OptionalNullable[float] = 1,
user: Optional[str] = None,
model_list: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[models.ReasoningEffort] = UNSET,
provider: OptionalNullable[
Union[models.Provider, models.ProviderTypedDict]
] = UNSET,
plugins: Optional[
Union[List[models.Plugin], List[models.PluginTypedDict]]
] = None,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[CompleteAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> models.ChatCompletion: ...
# endregion sdk-class-body
def complete(
self,
@@ -29,30 +141,16 @@ class Chat(BaseSDK):
metadata: Optional[Dict[str, str]] = None,
presence_penalty: OptionalNullable[float] = UNSET,
reasoning: OptionalNullable[
Union[
models.ChatCompletionCreateParamsReasoning,
models.ChatCompletionCreateParamsReasoningTypedDict,
]
Union[models.Reasoning, models.ReasoningTypedDict]
] = UNSET,
response_format: Optional[
Union[
models.ChatCompletionCreateParamsResponseFormatUnion,
models.ChatCompletionCreateParamsResponseFormatUnionTypedDict,
]
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
] = None,
seed: OptionalNullable[int] = UNSET,
stop: OptionalNullable[
Union[
models.ChatCompletionCreateParamsStop,
models.ChatCompletionCreateParamsStopTypedDict,
]
] = UNSET,
stop: OptionalNullable[Union[models.Stop, models.StopTypedDict]] = UNSET,
stream: OptionalNullable[bool] = False,
stream_options: OptionalNullable[
Union[
models.ChatCompletionCreateParamsStreamOptions,
models.ChatCompletionCreateParamsStreamOptionsTypedDict,
]
Union[models.StreamOptions, models.StreamOptionsTypedDict]
] = UNSET,
temperature: OptionalNullable[float] = 1,
tool_choice: Optional[
@@ -69,27 +167,20 @@ class Chat(BaseSDK):
] = None,
top_p: OptionalNullable[float] = 1,
user: Optional[str] = None,
models_llm: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[
models.ChatCompletionCreateParamsReasoningEffort
] = UNSET,
model_list: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[models.ReasoningEffort] = UNSET,
provider: OptionalNullable[
Union[
models.ChatCompletionCreateParamsProvider,
models.ChatCompletionCreateParamsProviderTypedDict,
]
Union[models.Provider, models.ProviderTypedDict]
] = UNSET,
plugins: Optional[
Union[
List[models.ChatCompletionCreateParamsPluginUnion],
List[models.ChatCompletionCreateParamsPluginUnionTypedDict],
]
Union[List[models.Plugin], List[models.PluginTypedDict]]
] = None,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[CompleteAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> models.ChatCompletion:
) -> models.CreateChatCompletionResponse:
r"""Create a chat completion
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
@@ -115,13 +206,14 @@ class Chat(BaseSDK):
:param tools: Available tools for function calling
:param top_p: Nucleus sampling parameter (0-1)
:param user: Unique user identifier
:param models_llm: Order of models to fallback to for this request
:param model_list: Order of models to fallback to for this request
:param reasoning_effort: Reasoning effort
:param provider: When multiple model providers are available, optionally indicate your routing preference.
:param plugins: Plugins you want to enable for this request, including their settings.
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param accept_header_override: Override the default accept header for this method
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
@@ -148,18 +240,16 @@ class Chat(BaseSDK):
metadata=metadata,
presence_penalty=presence_penalty,
reasoning=utils.get_pydantic_model(
reasoning, OptionalNullable[models.ChatCompletionCreateParamsReasoning]
reasoning, OptionalNullable[models.Reasoning]
),
response_format=utils.get_pydantic_model(
response_format,
Optional[models.ChatCompletionCreateParamsResponseFormatUnion],
response_format, Optional[models.ResponseFormat]
),
seed=seed,
stop=stop,
stream=stream,
stream_options=utils.get_pydantic_model(
stream_options,
OptionalNullable[models.ChatCompletionCreateParamsStreamOptions],
stream_options, OptionalNullable[models.StreamOptions]
),
temperature=temperature,
tool_choice=utils.get_pydantic_model(
@@ -170,14 +260,12 @@ class Chat(BaseSDK):
),
top_p=top_p,
user=user,
models_llm=models_llm,
model_list=model_list,
reasoning_effort=reasoning_effort,
provider=utils.get_pydantic_model(
provider, OptionalNullable[models.ChatCompletionCreateParamsProvider]
),
plugins=utils.get_pydantic_model(
plugins, Optional[List[models.ChatCompletionCreateParamsPluginUnion]]
provider, OptionalNullable[models.Provider]
),
plugins=utils.get_pydantic_model(plugins, Optional[List[models.Plugin]]),
)
req = self._build_request(
@@ -190,7 +278,9 @@ class Chat(BaseSDK):
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value="application/json",
accept_header_value=accept_header_override.value
if accept_header_override is not None
else "application/json;q=1, text/event-stream;q=0",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
@@ -219,493 +309,24 @@ class Chat(BaseSDK):
),
request=req,
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
retry_config=retry_config,
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
return unmarshal_json_response(models.ChatCompletion, http_res)
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "500", "application/json"):
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "4XX", "*"):
http_res_text = utils.stream_to_text(http_res)
raise errors.OpenRouterDefaultError(
"API error occurred", http_res, http_res_text
)
if utils.match_response(http_res, "5XX", "*"):
http_res_text = utils.stream_to_text(http_res)
raise errors.OpenRouterDefaultError(
"API error occurred", http_res, http_res_text
)
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
async def complete_async(
self,
*,
messages: Union[
List[models.ChatCompletionMessageParam],
List[models.ChatCompletionMessageParamTypedDict],
],
model: Optional[str] = None,
frequency_penalty: OptionalNullable[float] = UNSET,
logit_bias: OptionalNullable[Dict[str, float]] = UNSET,
logprobs: OptionalNullable[bool] = UNSET,
top_logprobs: OptionalNullable[float] = UNSET,
max_completion_tokens: OptionalNullable[float] = UNSET,
max_tokens: OptionalNullable[float] = UNSET,
metadata: Optional[Dict[str, str]] = None,
presence_penalty: OptionalNullable[float] = UNSET,
reasoning: OptionalNullable[
Union[
models.ChatCompletionCreateParamsReasoning,
models.ChatCompletionCreateParamsReasoningTypedDict,
]
] = UNSET,
response_format: Optional[
Union[
models.ChatCompletionCreateParamsResponseFormatUnion,
models.ChatCompletionCreateParamsResponseFormatUnionTypedDict,
]
] = None,
seed: OptionalNullable[int] = UNSET,
stop: OptionalNullable[
Union[
models.ChatCompletionCreateParamsStop,
models.ChatCompletionCreateParamsStopTypedDict,
]
] = UNSET,
stream: OptionalNullable[bool] = False,
stream_options: OptionalNullable[
Union[
models.ChatCompletionCreateParamsStreamOptions,
models.ChatCompletionCreateParamsStreamOptionsTypedDict,
]
] = UNSET,
temperature: OptionalNullable[float] = 1,
tool_choice: Optional[
Union[
models.ChatCompletionToolChoiceOption,
models.ChatCompletionToolChoiceOptionTypedDict,
]
] = None,
tools: Optional[
Union[
List[models.ChatCompletionTool],
List[models.ChatCompletionToolTypedDict],
]
] = None,
top_p: OptionalNullable[float] = 1,
user: Optional[str] = None,
models_llm: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[
models.ChatCompletionCreateParamsReasoningEffort
] = UNSET,
provider: OptionalNullable[
Union[
models.ChatCompletionCreateParamsProvider,
models.ChatCompletionCreateParamsProviderTypedDict,
]
] = UNSET,
plugins: Optional[
Union[
List[models.ChatCompletionCreateParamsPluginUnion],
List[models.ChatCompletionCreateParamsPluginUnionTypedDict],
]
] = None,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> models.ChatCompletion:
r"""Create a chat completion
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
:param messages: List of messages for the conversation
:param model: Model to use for completion
:param frequency_penalty: Frequency penalty (-2.0 to 2.0)
:param logit_bias: Token logit bias adjustments
:param logprobs: Return log probabilities
:param top_logprobs: Number of top log probabilities to return (0-20)
:param max_completion_tokens: Maximum tokens in completion
:param max_tokens: Maximum tokens (deprecated, use max_completion_tokens)
:param metadata: Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)
:param presence_penalty: Presence penalty (-2.0 to 2.0)
:param reasoning: Reasoning configuration
:param response_format: Response format configuration
:param seed: Random seed for deterministic outputs
:param stop: Stop sequences (up to 4)
:param stream: Enable streaming response
:param stream_options:
:param temperature: Sampling temperature (0-2)
:param tool_choice: Tool choice configuration
:param tools: Available tools for function calling
:param top_p: Nucleus sampling parameter (0-1)
:param user: Unique user identifier
:param models_llm: Order of models to fallback to for this request
:param reasoning_effort: Reasoning effort
:param provider: When multiple model providers are available, optionally indicate your routing preference.
:param plugins: Plugins you want to enable for this request, including their settings.
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
url_variables = None
if timeout_ms is None:
timeout_ms = self.sdk_configuration.timeout_ms
if server_url is not None:
base_url = server_url
else:
base_url = self._get_url(base_url, url_variables)
request = models.ChatCompletionCreateParams(
messages=utils.get_pydantic_model(
messages, List[models.ChatCompletionMessageParam]
),
model=model,
frequency_penalty=frequency_penalty,
logit_bias=logit_bias,
logprobs=logprobs,
top_logprobs=top_logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
metadata=metadata,
presence_penalty=presence_penalty,
reasoning=utils.get_pydantic_model(
reasoning, OptionalNullable[models.ChatCompletionCreateParamsReasoning]
),
response_format=utils.get_pydantic_model(
response_format,
Optional[models.ChatCompletionCreateParamsResponseFormatUnion],
),
seed=seed,
stop=stop,
stream=stream,
stream_options=utils.get_pydantic_model(
stream_options,
OptionalNullable[models.ChatCompletionCreateParamsStreamOptions],
),
temperature=temperature,
tool_choice=utils.get_pydantic_model(
tool_choice, Optional[models.ChatCompletionToolChoiceOption]
),
tools=utils.get_pydantic_model(
tools, Optional[List[models.ChatCompletionTool]]
),
top_p=top_p,
user=user,
models_llm=models_llm,
reasoning_effort=reasoning_effort,
provider=utils.get_pydantic_model(
provider, OptionalNullable[models.ChatCompletionCreateParamsProvider]
),
plugins=utils.get_pydantic_model(
plugins, Optional[List[models.ChatCompletionCreateParamsPluginUnion]]
),
)
req = self._build_request_async(
method="POST",
path="/chat/completions",
base_url=base_url,
url_variables=url_variables,
request=request,
request_body_required=True,
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value="application/json",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
request, False, False, "json", models.ChatCompletionCreateParams
),
timeout_ms=timeout_ms,
)
if retries == UNSET:
if self.sdk_configuration.retry_config is not UNSET:
retries = self.sdk_configuration.retry_config
retry_config = None
if isinstance(retries, utils.RetryConfig):
retry_config = (retries, ["429", "500", "502", "503", "504"])
http_res = await self.do_request_async(
hook_ctx=HookContext(
config=self.sdk_configuration,
base_url=base_url or "",
operation_id="createChatCompletion",
oauth2_scopes=[],
security_source=get_security_from_env(
self.sdk_configuration.security, models.Security
),
),
request=req,
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
retry_config=retry_config,
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
return unmarshal_json_response(models.ChatCompletion, http_res)
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "500", "application/json"):
response_data = unmarshal_json_response(
errors.ChatCompletionErrorData, http_res
)
raise errors.ChatCompletionError(response_data, http_res)
if utils.match_response(http_res, "4XX", "*"):
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.OpenRouterDefaultError(
"API error occurred", http_res, http_res_text
)
if utils.match_response(http_res, "5XX", "*"):
http_res_text = await utils.stream_to_text_async(http_res)
raise errors.OpenRouterDefaultError(
"API error occurred", http_res, http_res_text
)
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
def complete_stream(
self,
*,
messages: Union[
List[models.ChatCompletionMessageParam],
List[models.ChatCompletionMessageParamTypedDict],
],
model: Optional[str] = None,
frequency_penalty: OptionalNullable[float] = UNSET,
logit_bias: OptionalNullable[Dict[str, float]] = UNSET,
logprobs: OptionalNullable[bool] = UNSET,
top_logprobs: OptionalNullable[float] = UNSET,
max_completion_tokens: OptionalNullable[float] = UNSET,
max_tokens: OptionalNullable[float] = UNSET,
metadata: Optional[Dict[str, str]] = None,
presence_penalty: OptionalNullable[float] = UNSET,
reasoning: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsReasoning,
models.ChatStreamCompletionCreateParamsReasoningTypedDict,
]
] = UNSET,
response_format: Optional[
Union[
models.ChatStreamCompletionCreateParamsResponseFormatUnion,
models.ChatStreamCompletionCreateParamsResponseFormatUnionTypedDict,
]
] = None,
seed: OptionalNullable[int] = UNSET,
stop: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsStop,
models.ChatStreamCompletionCreateParamsStopTypedDict,
]
] = UNSET,
stream: Optional[bool] = True,
stream_options: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsStreamOptions,
models.ChatStreamCompletionCreateParamsStreamOptionsTypedDict,
]
] = UNSET,
temperature: OptionalNullable[float] = 1,
tool_choice: Optional[
Union[
models.ChatCompletionToolChoiceOption,
models.ChatCompletionToolChoiceOptionTypedDict,
]
] = None,
tools: Optional[
Union[
List[models.ChatCompletionTool],
List[models.ChatCompletionToolTypedDict],
]
] = None,
top_p: OptionalNullable[float] = 1,
user: Optional[str] = None,
models_llm: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[
models.ChatStreamCompletionCreateParamsReasoningEffort
] = UNSET,
provider: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsProvider,
models.ChatStreamCompletionCreateParamsProviderTypedDict,
]
] = UNSET,
plugins: Optional[
Union[
List[models.ChatStreamCompletionCreateParamsPluginUnion],
List[models.ChatStreamCompletionCreateParamsPluginUnionTypedDict],
]
] = None,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> eventstreaming.EventStream[models.StreamChatCompletionResponseBody]:
r"""Create a chat completion
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
:param messages: List of messages for the conversation
:param model: Model to use for completion
:param frequency_penalty: Frequency penalty (-2.0 to 2.0)
:param logit_bias: Token logit bias adjustments
:param logprobs: Return log probabilities
:param top_logprobs: Number of top log probabilities to return (0-20)
:param max_completion_tokens: Maximum tokens in completion
:param max_tokens: Maximum tokens (deprecated, use max_completion_tokens)
:param metadata: Key-value pairs for additional object information (max 16 pairs, 64 char keys, 512 char values)
:param presence_penalty: Presence penalty (-2.0 to 2.0)
:param reasoning: Reasoning configuration
:param response_format: Response format configuration
:param seed: Random seed for deterministic outputs
:param stop: Stop sequences (up to 4)
:param stream: Enable streaming response
:param stream_options:
:param temperature: Sampling temperature (0-2)
:param tool_choice: Tool choice configuration
:param tools: Available tools for function calling
:param top_p: Nucleus sampling parameter (0-1)
:param user: Unique user identifier
:param models_llm: Order of models to fallback to for this request
:param reasoning_effort: Reasoning effort
:param provider: When multiple model providers are available, optionally indicate your routing preference.
:param plugins: Plugins you want to enable for this request, including their settings.
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
url_variables = None
if timeout_ms is None:
timeout_ms = self.sdk_configuration.timeout_ms
if server_url is not None:
base_url = server_url
else:
base_url = self._get_url(base_url, url_variables)
request = models.ChatStreamCompletionCreateParams(
messages=utils.get_pydantic_model(
messages, List[models.ChatCompletionMessageParam]
),
model=model,
frequency_penalty=frequency_penalty,
logit_bias=logit_bias,
logprobs=logprobs,
top_logprobs=top_logprobs,
max_completion_tokens=max_completion_tokens,
max_tokens=max_tokens,
metadata=metadata,
presence_penalty=presence_penalty,
reasoning=utils.get_pydantic_model(
reasoning,
OptionalNullable[models.ChatStreamCompletionCreateParamsReasoning],
),
response_format=utils.get_pydantic_model(
response_format,
Optional[models.ChatStreamCompletionCreateParamsResponseFormatUnion],
),
seed=seed,
stop=stop,
stream=stream,
stream_options=utils.get_pydantic_model(
stream_options,
OptionalNullable[models.ChatStreamCompletionCreateParamsStreamOptions],
),
temperature=temperature,
tool_choice=utils.get_pydantic_model(
tool_choice, Optional[models.ChatCompletionToolChoiceOption]
),
tools=utils.get_pydantic_model(
tools, Optional[List[models.ChatCompletionTool]]
),
top_p=top_p,
user=user,
models_llm=models_llm,
reasoning_effort=reasoning_effort,
provider=utils.get_pydantic_model(
provider,
OptionalNullable[models.ChatStreamCompletionCreateParamsProvider],
),
plugins=utils.get_pydantic_model(
plugins,
Optional[List[models.ChatStreamCompletionCreateParamsPluginUnion]],
),
)
req = self._build_request(
method="POST",
path="/chat/completions#stream",
base_url=base_url,
url_variables=url_variables,
request=request,
request_body_required=True,
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value="text/event-stream",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
request, False, False, "json", models.ChatStreamCompletionCreateParams
),
timeout_ms=timeout_ms,
)
if retries == UNSET:
if self.sdk_configuration.retry_config is not UNSET:
retries = self.sdk_configuration.retry_config
retry_config = None
if isinstance(retries, utils.RetryConfig):
retry_config = (retries, ["429", "500", "502", "503", "504"])
http_res = self.do_request(
hook_ctx=HookContext(
config=self.sdk_configuration,
base_url=base_url or "",
operation_id="streamChatCompletion",
oauth2_scopes=[],
security_source=get_security_from_env(
self.sdk_configuration.security, models.Security
),
),
request=req,
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
stream=True,
retry_config=retry_config,
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
http_res_text = utils.stream_to_text(http_res)
return unmarshal_json_response(
models.ChatCompletion, http_res, http_res_text
)
if utils.match_response(http_res, "200", "text/event-stream"):
return eventstreaming.EventStream(
http_res,
lambda raw: utils.unmarshal_json(
raw, models.StreamChatCompletionResponseBody
raw, models.ChatCompletionChunkWrapper
),
sentinel="[DONE]",
client_ref=self,
)
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
http_res_text = utils.stream_to_text(http_res)
@@ -735,7 +356,7 @@ class Chat(BaseSDK):
"Unexpected response received", http_res, http_res_text
)
async def complete_stream_async(
async def complete_async(
self,
*,
messages: Union[
@@ -752,30 +373,16 @@ class Chat(BaseSDK):
metadata: Optional[Dict[str, str]] = None,
presence_penalty: OptionalNullable[float] = UNSET,
reasoning: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsReasoning,
models.ChatStreamCompletionCreateParamsReasoningTypedDict,
]
Union[models.Reasoning, models.ReasoningTypedDict]
] = UNSET,
response_format: Optional[
Union[
models.ChatStreamCompletionCreateParamsResponseFormatUnion,
models.ChatStreamCompletionCreateParamsResponseFormatUnionTypedDict,
]
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
] = None,
seed: OptionalNullable[int] = UNSET,
stop: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsStop,
models.ChatStreamCompletionCreateParamsStopTypedDict,
]
] = UNSET,
stream: Optional[bool] = True,
stop: OptionalNullable[Union[models.Stop, models.StopTypedDict]] = UNSET,
stream: OptionalNullable[bool] = False,
stream_options: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsStreamOptions,
models.ChatStreamCompletionCreateParamsStreamOptionsTypedDict,
]
Union[models.StreamOptions, models.StreamOptionsTypedDict]
] = UNSET,
temperature: OptionalNullable[float] = 1,
tool_choice: Optional[
@@ -792,27 +399,20 @@ class Chat(BaseSDK):
] = None,
top_p: OptionalNullable[float] = 1,
user: Optional[str] = None,
models_llm: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[
models.ChatStreamCompletionCreateParamsReasoningEffort
] = UNSET,
model_list: OptionalNullable[List[str]] = UNSET,
reasoning_effort: OptionalNullable[models.ReasoningEffort] = UNSET,
provider: OptionalNullable[
Union[
models.ChatStreamCompletionCreateParamsProvider,
models.ChatStreamCompletionCreateParamsProviderTypedDict,
]
Union[models.Provider, models.ProviderTypedDict]
] = UNSET,
plugins: Optional[
Union[
List[models.ChatStreamCompletionCreateParamsPluginUnion],
List[models.ChatStreamCompletionCreateParamsPluginUnionTypedDict],
]
Union[List[models.Plugin], List[models.PluginTypedDict]]
] = None,
retries: OptionalNullable[utils.RetryConfig] = UNSET,
server_url: Optional[str] = None,
timeout_ms: Optional[int] = None,
accept_header_override: Optional[CompleteAcceptEnum] = None,
http_headers: Optional[Mapping[str, str]] = None,
) -> eventstreaming.EventStreamAsync[models.StreamChatCompletionResponseBody]:
) -> models.CreateChatCompletionResponse:
r"""Create a chat completion
Creates a model response for the given chat conversation. Supports both streaming and non-streaming modes.
@@ -838,13 +438,14 @@ class Chat(BaseSDK):
:param tools: Available tools for function calling
:param top_p: Nucleus sampling parameter (0-1)
:param user: Unique user identifier
:param models_llm: Order of models to fallback to for this request
:param model_list: Order of models to fallback to for this request
:param reasoning_effort: Reasoning effort
:param provider: When multiple model providers are available, optionally indicate your routing preference.
:param plugins: Plugins you want to enable for this request, including their settings.
:param retries: Override the default retry configuration for this method
:param server_url: Override the default server URL for this method
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
:param accept_header_override: Override the default accept header for this method
:param http_headers: Additional headers to set or replace on requests.
"""
base_url = None
@@ -857,7 +458,7 @@ class Chat(BaseSDK):
else:
base_url = self._get_url(base_url, url_variables)
request = models.ChatStreamCompletionCreateParams(
request = models.ChatCompletionCreateParams(
messages=utils.get_pydantic_model(
messages, List[models.ChatCompletionMessageParam]
),
@@ -871,19 +472,16 @@ class Chat(BaseSDK):
metadata=metadata,
presence_penalty=presence_penalty,
reasoning=utils.get_pydantic_model(
reasoning,
OptionalNullable[models.ChatStreamCompletionCreateParamsReasoning],
reasoning, OptionalNullable[models.Reasoning]
),
response_format=utils.get_pydantic_model(
response_format,
Optional[models.ChatStreamCompletionCreateParamsResponseFormatUnion],
response_format, Optional[models.ResponseFormat]
),
seed=seed,
stop=stop,
stream=stream,
stream_options=utils.get_pydantic_model(
stream_options,
OptionalNullable[models.ChatStreamCompletionCreateParamsStreamOptions],
stream_options, OptionalNullable[models.StreamOptions]
),
temperature=temperature,
tool_choice=utils.get_pydantic_model(
@@ -894,21 +492,17 @@ class Chat(BaseSDK):
),
top_p=top_p,
user=user,
models_llm=models_llm,
model_list=model_list,
reasoning_effort=reasoning_effort,
provider=utils.get_pydantic_model(
provider,
OptionalNullable[models.ChatStreamCompletionCreateParamsProvider],
),
plugins=utils.get_pydantic_model(
plugins,
Optional[List[models.ChatStreamCompletionCreateParamsPluginUnion]],
provider, OptionalNullable[models.Provider]
),
plugins=utils.get_pydantic_model(plugins, Optional[List[models.Plugin]]),
)
req = self._build_request_async(
method="POST",
path="/chat/completions#stream",
path="/chat/completions",
base_url=base_url,
url_variables=url_variables,
request=request,
@@ -916,11 +510,13 @@ class Chat(BaseSDK):
request_has_path_params=False,
request_has_query_params=True,
user_agent_header="user-agent",
accept_header_value="text/event-stream",
accept_header_value=accept_header_override.value
if accept_header_override is not None
else "application/json;q=1, text/event-stream;q=0",
http_headers=http_headers,
security=self.sdk_configuration.security,
get_serialized_body=lambda: utils.serialize_request_body(
request, False, False, "json", models.ChatStreamCompletionCreateParams
request, False, False, "json", models.ChatCompletionCreateParams
),
timeout_ms=timeout_ms,
)
@@ -937,7 +533,7 @@ class Chat(BaseSDK):
hook_ctx=HookContext(
config=self.sdk_configuration,
base_url=base_url or "",
operation_id="streamChatCompletion",
operation_id="createChatCompletion",
oauth2_scopes=[],
security_source=get_security_from_env(
self.sdk_configuration.security, models.Security
@@ -950,13 +546,19 @@ class Chat(BaseSDK):
)
response_data: Any = None
if utils.match_response(http_res, "200", "application/json"):
http_res_text = await utils.stream_to_text_async(http_res)
return unmarshal_json_response(
models.ChatCompletion, http_res, http_res_text
)
if utils.match_response(http_res, "200", "text/event-stream"):
return eventstreaming.EventStreamAsync(
http_res,
lambda raw: utils.unmarshal_json(
raw, models.StreamChatCompletionResponseBody
raw, models.ChatCompletionChunkWrapper
),
sentinel="[DONE]",
client_ref=self,
)
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
http_res_text = await utils.stream_to_text_async(http_res)
+15 -3
View File
@@ -1,14 +1,15 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from .openroutererror import OpenRouterError
from typing import TYPE_CHECKING
from importlib import import_module
import builtins
import sys
if TYPE_CHECKING:
from .chatcompletionerror import ChatCompletionError, ChatCompletionErrorData
from .no_response_error import NoResponseError
from .openrouterdefaulterror import OpenRouterDefaultError
from .openroutererror import OpenRouterError
from .responsevalidationerror import ResponseValidationError
__all__ = [
@@ -25,11 +26,22 @@ _dynamic_imports: dict[str, str] = {
"ChatCompletionErrorData": ".chatcompletionerror",
"NoResponseError": ".no_response_error",
"OpenRouterDefaultError": ".openrouterdefaulterror",
"OpenRouterError": ".openroutererror",
"ResponseValidationError": ".responsevalidationerror",
}
def dynamic_import(modname, retries=3):
for attempt in range(retries):
try:
return import_module(modname, __package__)
except KeyError:
# Clear any half-initialized module and retry
sys.modules.pop(modname, None)
if attempt == retries - 1:
break
raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
def __getattr__(attr_name: str) -> object:
module_name = _dynamic_imports.get(attr_name)
if module_name is None:
@@ -38,7 +50,7 @@ def __getattr__(attr_name: str) -> object:
)
try:
module = import_module(module_name, __package__)
module = dynamic_import(module_name)
result = getattr(module, attr_name)
return result
except ImportError as e:
+240 -440
View File
@@ -3,6 +3,7 @@
from typing import TYPE_CHECKING
from importlib import import_module
import builtins
import sys
if TYPE_CHECKING:
from .annotationdetail import AnnotationDetail, AnnotationDetailTypedDict
@@ -45,6 +46,10 @@ if TYPE_CHECKING:
ChatCompletionChunkChoiceDeltaToolCallType,
ChatCompletionChunkChoiceDeltaToolCallTypedDict,
)
from .chatcompletionchunkwrapper import (
ChatCompletionChunkWrapper,
ChatCompletionChunkWrapperTypedDict,
)
from .chatcompletioncontentpart import (
ChatCompletionContentPart,
ChatCompletionContentPartTypedDict,
@@ -71,79 +76,79 @@ if TYPE_CHECKING:
ChatCompletionContentPartTextTypedDict,
)
from .chatcompletioncreateparams import (
Audio,
AudioTypedDict,
ChatCompletionCreateParams,
ChatCompletionCreateParamsAudio,
ChatCompletionCreateParamsAudioTypedDict,
ChatCompletionCreateParamsCompletion,
ChatCompletionCreateParamsCompletionTypedDict,
ChatCompletionCreateParamsDataCollection,
ChatCompletionCreateParamsEffort,
ChatCompletionCreateParamsEngine,
ChatCompletionCreateParamsIDChainOfThought,
ChatCompletionCreateParamsIDFileParser,
ChatCompletionCreateParamsIDModeration,
ChatCompletionCreateParamsIDWeb,
ChatCompletionCreateParamsIgnoreEnum,
ChatCompletionCreateParamsIgnoreUnion,
ChatCompletionCreateParamsIgnoreUnionTypedDict,
ChatCompletionCreateParamsImage,
ChatCompletionCreateParamsImageTypedDict,
ChatCompletionCreateParamsJSONSchema,
ChatCompletionCreateParamsJSONSchemaTypedDict,
ChatCompletionCreateParamsMaxPrice,
ChatCompletionCreateParamsMaxPriceTypedDict,
ChatCompletionCreateParamsOnlyEnum,
ChatCompletionCreateParamsOnlyUnion,
ChatCompletionCreateParamsOnlyUnionTypedDict,
ChatCompletionCreateParamsOrderEnum,
ChatCompletionCreateParamsOrderUnion,
ChatCompletionCreateParamsOrderUnionTypedDict,
ChatCompletionCreateParamsPdf,
ChatCompletionCreateParamsPdfEngine,
ChatCompletionCreateParamsPdfTypedDict,
ChatCompletionCreateParamsPluginChainOfThought,
ChatCompletionCreateParamsPluginChainOfThoughtTypedDict,
ChatCompletionCreateParamsPluginFileParser,
ChatCompletionCreateParamsPluginFileParserTypedDict,
ChatCompletionCreateParamsPluginModeration,
ChatCompletionCreateParamsPluginModerationTypedDict,
ChatCompletionCreateParamsPluginUnion,
ChatCompletionCreateParamsPluginUnionTypedDict,
ChatCompletionCreateParamsPluginWeb,
ChatCompletionCreateParamsPluginWebTypedDict,
ChatCompletionCreateParamsPrompt,
ChatCompletionCreateParamsPromptTypedDict,
ChatCompletionCreateParamsProvider,
ChatCompletionCreateParamsProviderTypedDict,
ChatCompletionCreateParamsQuantization,
ChatCompletionCreateParamsReasoning,
ChatCompletionCreateParamsReasoningEffort,
ChatCompletionCreateParamsReasoningTypedDict,
ChatCompletionCreateParamsRequest,
ChatCompletionCreateParamsRequestTypedDict,
ChatCompletionCreateParamsResponseFormatGrammar,
ChatCompletionCreateParamsResponseFormatGrammarTypedDict,
ChatCompletionCreateParamsResponseFormatJSONObject,
ChatCompletionCreateParamsResponseFormatJSONObjectTypedDict,
ChatCompletionCreateParamsResponseFormatJSONSchema,
ChatCompletionCreateParamsResponseFormatJSONSchemaTypedDict,
ChatCompletionCreateParamsResponseFormatPython,
ChatCompletionCreateParamsResponseFormatPythonTypedDict,
ChatCompletionCreateParamsResponseFormatText,
ChatCompletionCreateParamsResponseFormatTextTypedDict,
ChatCompletionCreateParamsResponseFormatUnion,
ChatCompletionCreateParamsResponseFormatUnionTypedDict,
ChatCompletionCreateParamsSort,
ChatCompletionCreateParamsStop,
ChatCompletionCreateParamsStopTypedDict,
ChatCompletionCreateParamsStreamOptions,
ChatCompletionCreateParamsStreamOptionsTypedDict,
ChatCompletionCreateParamsTypeGrammar,
ChatCompletionCreateParamsTypeJSONObject,
ChatCompletionCreateParamsTypeJSONSchema,
ChatCompletionCreateParamsTypePython,
ChatCompletionCreateParamsTypeText,
ChatCompletionCreateParamsTypedDict,
Completion,
CompletionTypedDict,
DataCollection,
Effort,
Engine,
IDChainOfThought,
IDFileParser,
IDModeration,
IDWeb,
Ignore,
IgnoreEnum,
IgnoreTypedDict,
Image,
ImageTypedDict,
JSONSchema,
JSONSchemaTypedDict,
MaxPrice,
MaxPriceTypedDict,
Only,
OnlyEnum,
OnlyTypedDict,
Order,
OrderEnum,
OrderTypedDict,
Pdf,
PdfEngine,
PdfTypedDict,
Plugin,
PluginChainOfThought,
PluginChainOfThoughtTypedDict,
PluginFileParser,
PluginFileParserTypedDict,
PluginModeration,
PluginModerationTypedDict,
PluginTypedDict,
PluginWeb,
PluginWebTypedDict,
Prompt,
PromptTypedDict,
Provider,
ProviderTypedDict,
Quantization,
Reasoning,
ReasoningEffort,
ReasoningTypedDict,
Request,
RequestTypedDict,
ResponseFormat,
ResponseFormatGrammar,
ResponseFormatGrammarTypedDict,
ResponseFormatJSONObject,
ResponseFormatJSONObjectTypedDict,
ResponseFormatJSONSchema,
ResponseFormatJSONSchemaTypedDict,
ResponseFormatPython,
ResponseFormatPythonTypedDict,
ResponseFormatText,
ResponseFormatTextTypedDict,
ResponseFormatTypedDict,
Sort,
Stop,
StopTypedDict,
StreamOptions,
StreamOptionsTypedDict,
TypeGrammar,
TypeJSONObject,
TypeJSONSchema,
TypePython,
)
from .chatcompletionerror import Error, ErrorTypedDict
from .chatcompletionmessage import (
@@ -216,81 +221,6 @@ if TYPE_CHECKING:
ChatCompletionUserMessageParamRole,
ChatCompletionUserMessageParamTypedDict,
)
from .chatstreamcompletioncreateparams import (
ChatStreamCompletionCreateParams,
ChatStreamCompletionCreateParamsAudio,
ChatStreamCompletionCreateParamsAudioTypedDict,
ChatStreamCompletionCreateParamsCompletion,
ChatStreamCompletionCreateParamsCompletionTypedDict,
ChatStreamCompletionCreateParamsDataCollection,
ChatStreamCompletionCreateParamsEffort,
ChatStreamCompletionCreateParamsEngine,
ChatStreamCompletionCreateParamsIDChainOfThought,
ChatStreamCompletionCreateParamsIDFileParser,
ChatStreamCompletionCreateParamsIDModeration,
ChatStreamCompletionCreateParamsIDWeb,
ChatStreamCompletionCreateParamsIgnoreEnum,
ChatStreamCompletionCreateParamsIgnoreUnion,
ChatStreamCompletionCreateParamsIgnoreUnionTypedDict,
ChatStreamCompletionCreateParamsImage,
ChatStreamCompletionCreateParamsImageTypedDict,
ChatStreamCompletionCreateParamsJSONSchema,
ChatStreamCompletionCreateParamsJSONSchemaTypedDict,
ChatStreamCompletionCreateParamsMaxPrice,
ChatStreamCompletionCreateParamsMaxPriceTypedDict,
ChatStreamCompletionCreateParamsOnlyEnum,
ChatStreamCompletionCreateParamsOnlyUnion,
ChatStreamCompletionCreateParamsOnlyUnionTypedDict,
ChatStreamCompletionCreateParamsOrderEnum,
ChatStreamCompletionCreateParamsOrderUnion,
ChatStreamCompletionCreateParamsOrderUnionTypedDict,
ChatStreamCompletionCreateParamsPdf,
ChatStreamCompletionCreateParamsPdfEngine,
ChatStreamCompletionCreateParamsPdfTypedDict,
ChatStreamCompletionCreateParamsPluginChainOfThought,
ChatStreamCompletionCreateParamsPluginChainOfThoughtTypedDict,
ChatStreamCompletionCreateParamsPluginFileParser,
ChatStreamCompletionCreateParamsPluginFileParserTypedDict,
ChatStreamCompletionCreateParamsPluginModeration,
ChatStreamCompletionCreateParamsPluginModerationTypedDict,
ChatStreamCompletionCreateParamsPluginUnion,
ChatStreamCompletionCreateParamsPluginUnionTypedDict,
ChatStreamCompletionCreateParamsPluginWeb,
ChatStreamCompletionCreateParamsPluginWebTypedDict,
ChatStreamCompletionCreateParamsPrompt,
ChatStreamCompletionCreateParamsPromptTypedDict,
ChatStreamCompletionCreateParamsProvider,
ChatStreamCompletionCreateParamsProviderTypedDict,
ChatStreamCompletionCreateParamsQuantization,
ChatStreamCompletionCreateParamsReasoning,
ChatStreamCompletionCreateParamsReasoningEffort,
ChatStreamCompletionCreateParamsReasoningTypedDict,
ChatStreamCompletionCreateParamsRequest,
ChatStreamCompletionCreateParamsRequestTypedDict,
ChatStreamCompletionCreateParamsResponseFormatGrammar,
ChatStreamCompletionCreateParamsResponseFormatGrammarTypedDict,
ChatStreamCompletionCreateParamsResponseFormatJSONObject,
ChatStreamCompletionCreateParamsResponseFormatJSONObjectTypedDict,
ChatStreamCompletionCreateParamsResponseFormatJSONSchema,
ChatStreamCompletionCreateParamsResponseFormatJSONSchemaTypedDict,
ChatStreamCompletionCreateParamsResponseFormatPython,
ChatStreamCompletionCreateParamsResponseFormatPythonTypedDict,
ChatStreamCompletionCreateParamsResponseFormatText,
ChatStreamCompletionCreateParamsResponseFormatTextTypedDict,
ChatStreamCompletionCreateParamsResponseFormatUnion,
ChatStreamCompletionCreateParamsResponseFormatUnionTypedDict,
ChatStreamCompletionCreateParamsSort,
ChatStreamCompletionCreateParamsStop,
ChatStreamCompletionCreateParamsStopTypedDict,
ChatStreamCompletionCreateParamsStreamOptions,
ChatStreamCompletionCreateParamsStreamOptionsTypedDict,
ChatStreamCompletionCreateParamsTypeGrammar,
ChatStreamCompletionCreateParamsTypeJSONObject,
ChatStreamCompletionCreateParamsTypeJSONSchema,
ChatStreamCompletionCreateParamsTypePython,
ChatStreamCompletionCreateParamsTypeText,
ChatStreamCompletionCreateParamsTypedDict,
)
from .completionusage import (
CompletionTokensDetails,
CompletionTokensDetailsTypedDict,
@@ -299,6 +229,10 @@ if TYPE_CHECKING:
PromptTokensDetails,
PromptTokensDetailsTypedDict,
)
from .createchatcompletionop import (
CreateChatCompletionResponse,
CreateChatCompletionResponseTypedDict,
)
from .fileannotationdetail import (
ContentImageURL,
ContentImageURLTypedDict,
@@ -340,10 +274,6 @@ if TYPE_CHECKING:
ResponseFormatJSONSchemaSchemaTypedDict,
)
from .security import Security, SecurityTypedDict
from .streamchatcompletionop import (
StreamChatCompletionResponseBody,
StreamChatCompletionResponseBodyTypedDict,
)
from .urlcitationannotationdetail import (
URLCitation,
URLCitationAnnotationDetail,
@@ -355,6 +285,8 @@ if TYPE_CHECKING:
__all__ = [
"AnnotationDetail",
"AnnotationDetailTypedDict",
"Audio",
"AudioTypedDict",
"ChatCompletion",
"ChatCompletionAssistantMessageParam",
"ChatCompletionAssistantMessageParamContent",
@@ -378,6 +310,8 @@ __all__ = [
"ChatCompletionChunkChoiceTypedDict",
"ChatCompletionChunkObject",
"ChatCompletionChunkTypedDict",
"ChatCompletionChunkWrapper",
"ChatCompletionChunkWrapperTypedDict",
"ChatCompletionContentPart",
"ChatCompletionContentPartAudio",
"ChatCompletionContentPartAudioFormat",
@@ -393,76 +327,6 @@ __all__ = [
"ChatCompletionContentPartTextTypedDict",
"ChatCompletionContentPartTypedDict",
"ChatCompletionCreateParams",
"ChatCompletionCreateParamsAudio",
"ChatCompletionCreateParamsAudioTypedDict",
"ChatCompletionCreateParamsCompletion",
"ChatCompletionCreateParamsCompletionTypedDict",
"ChatCompletionCreateParamsDataCollection",
"ChatCompletionCreateParamsEffort",
"ChatCompletionCreateParamsEngine",
"ChatCompletionCreateParamsIDChainOfThought",
"ChatCompletionCreateParamsIDFileParser",
"ChatCompletionCreateParamsIDModeration",
"ChatCompletionCreateParamsIDWeb",
"ChatCompletionCreateParamsIgnoreEnum",
"ChatCompletionCreateParamsIgnoreUnion",
"ChatCompletionCreateParamsIgnoreUnionTypedDict",
"ChatCompletionCreateParamsImage",
"ChatCompletionCreateParamsImageTypedDict",
"ChatCompletionCreateParamsJSONSchema",
"ChatCompletionCreateParamsJSONSchemaTypedDict",
"ChatCompletionCreateParamsMaxPrice",
"ChatCompletionCreateParamsMaxPriceTypedDict",
"ChatCompletionCreateParamsOnlyEnum",
"ChatCompletionCreateParamsOnlyUnion",
"ChatCompletionCreateParamsOnlyUnionTypedDict",
"ChatCompletionCreateParamsOrderEnum",
"ChatCompletionCreateParamsOrderUnion",
"ChatCompletionCreateParamsOrderUnionTypedDict",
"ChatCompletionCreateParamsPdf",
"ChatCompletionCreateParamsPdfEngine",
"ChatCompletionCreateParamsPdfTypedDict",
"ChatCompletionCreateParamsPluginChainOfThought",
"ChatCompletionCreateParamsPluginChainOfThoughtTypedDict",
"ChatCompletionCreateParamsPluginFileParser",
"ChatCompletionCreateParamsPluginFileParserTypedDict",
"ChatCompletionCreateParamsPluginModeration",
"ChatCompletionCreateParamsPluginModerationTypedDict",
"ChatCompletionCreateParamsPluginUnion",
"ChatCompletionCreateParamsPluginUnionTypedDict",
"ChatCompletionCreateParamsPluginWeb",
"ChatCompletionCreateParamsPluginWebTypedDict",
"ChatCompletionCreateParamsPrompt",
"ChatCompletionCreateParamsPromptTypedDict",
"ChatCompletionCreateParamsProvider",
"ChatCompletionCreateParamsProviderTypedDict",
"ChatCompletionCreateParamsQuantization",
"ChatCompletionCreateParamsReasoning",
"ChatCompletionCreateParamsReasoningEffort",
"ChatCompletionCreateParamsReasoningTypedDict",
"ChatCompletionCreateParamsRequest",
"ChatCompletionCreateParamsRequestTypedDict",
"ChatCompletionCreateParamsResponseFormatGrammar",
"ChatCompletionCreateParamsResponseFormatGrammarTypedDict",
"ChatCompletionCreateParamsResponseFormatJSONObject",
"ChatCompletionCreateParamsResponseFormatJSONObjectTypedDict",
"ChatCompletionCreateParamsResponseFormatJSONSchema",
"ChatCompletionCreateParamsResponseFormatJSONSchemaTypedDict",
"ChatCompletionCreateParamsResponseFormatPython",
"ChatCompletionCreateParamsResponseFormatPythonTypedDict",
"ChatCompletionCreateParamsResponseFormatText",
"ChatCompletionCreateParamsResponseFormatTextTypedDict",
"ChatCompletionCreateParamsResponseFormatUnion",
"ChatCompletionCreateParamsResponseFormatUnionTypedDict",
"ChatCompletionCreateParamsSort",
"ChatCompletionCreateParamsStop",
"ChatCompletionCreateParamsStopTypedDict",
"ChatCompletionCreateParamsStreamOptions",
"ChatCompletionCreateParamsStreamOptionsTypedDict",
"ChatCompletionCreateParamsTypeGrammar",
"ChatCompletionCreateParamsTypeJSONObject",
"ChatCompletionCreateParamsTypeJSONSchema",
"ChatCompletionCreateParamsTypePython",
"ChatCompletionCreateParamsTypeText",
"ChatCompletionCreateParamsTypedDict",
"ChatCompletionMessage",
@@ -511,81 +375,10 @@ __all__ = [
"ChatCompletionUserMessageParamContentTypedDict",
"ChatCompletionUserMessageParamRole",
"ChatCompletionUserMessageParamTypedDict",
"ChatStreamCompletionCreateParams",
"ChatStreamCompletionCreateParamsAudio",
"ChatStreamCompletionCreateParamsAudioTypedDict",
"ChatStreamCompletionCreateParamsCompletion",
"ChatStreamCompletionCreateParamsCompletionTypedDict",
"ChatStreamCompletionCreateParamsDataCollection",
"ChatStreamCompletionCreateParamsEffort",
"ChatStreamCompletionCreateParamsEngine",
"ChatStreamCompletionCreateParamsIDChainOfThought",
"ChatStreamCompletionCreateParamsIDFileParser",
"ChatStreamCompletionCreateParamsIDModeration",
"ChatStreamCompletionCreateParamsIDWeb",
"ChatStreamCompletionCreateParamsIgnoreEnum",
"ChatStreamCompletionCreateParamsIgnoreUnion",
"ChatStreamCompletionCreateParamsIgnoreUnionTypedDict",
"ChatStreamCompletionCreateParamsImage",
"ChatStreamCompletionCreateParamsImageTypedDict",
"ChatStreamCompletionCreateParamsJSONSchema",
"ChatStreamCompletionCreateParamsJSONSchemaTypedDict",
"ChatStreamCompletionCreateParamsMaxPrice",
"ChatStreamCompletionCreateParamsMaxPriceTypedDict",
"ChatStreamCompletionCreateParamsOnlyEnum",
"ChatStreamCompletionCreateParamsOnlyUnion",
"ChatStreamCompletionCreateParamsOnlyUnionTypedDict",
"ChatStreamCompletionCreateParamsOrderEnum",
"ChatStreamCompletionCreateParamsOrderUnion",
"ChatStreamCompletionCreateParamsOrderUnionTypedDict",
"ChatStreamCompletionCreateParamsPdf",
"ChatStreamCompletionCreateParamsPdfEngine",
"ChatStreamCompletionCreateParamsPdfTypedDict",
"ChatStreamCompletionCreateParamsPluginChainOfThought",
"ChatStreamCompletionCreateParamsPluginChainOfThoughtTypedDict",
"ChatStreamCompletionCreateParamsPluginFileParser",
"ChatStreamCompletionCreateParamsPluginFileParserTypedDict",
"ChatStreamCompletionCreateParamsPluginModeration",
"ChatStreamCompletionCreateParamsPluginModerationTypedDict",
"ChatStreamCompletionCreateParamsPluginUnion",
"ChatStreamCompletionCreateParamsPluginUnionTypedDict",
"ChatStreamCompletionCreateParamsPluginWeb",
"ChatStreamCompletionCreateParamsPluginWebTypedDict",
"ChatStreamCompletionCreateParamsPrompt",
"ChatStreamCompletionCreateParamsPromptTypedDict",
"ChatStreamCompletionCreateParamsProvider",
"ChatStreamCompletionCreateParamsProviderTypedDict",
"ChatStreamCompletionCreateParamsQuantization",
"ChatStreamCompletionCreateParamsReasoning",
"ChatStreamCompletionCreateParamsReasoningEffort",
"ChatStreamCompletionCreateParamsReasoningTypedDict",
"ChatStreamCompletionCreateParamsRequest",
"ChatStreamCompletionCreateParamsRequestTypedDict",
"ChatStreamCompletionCreateParamsResponseFormatGrammar",
"ChatStreamCompletionCreateParamsResponseFormatGrammarTypedDict",
"ChatStreamCompletionCreateParamsResponseFormatJSONObject",
"ChatStreamCompletionCreateParamsResponseFormatJSONObjectTypedDict",
"ChatStreamCompletionCreateParamsResponseFormatJSONSchema",
"ChatStreamCompletionCreateParamsResponseFormatJSONSchemaTypedDict",
"ChatStreamCompletionCreateParamsResponseFormatPython",
"ChatStreamCompletionCreateParamsResponseFormatPythonTypedDict",
"ChatStreamCompletionCreateParamsResponseFormatText",
"ChatStreamCompletionCreateParamsResponseFormatTextTypedDict",
"ChatStreamCompletionCreateParamsResponseFormatUnion",
"ChatStreamCompletionCreateParamsResponseFormatUnionTypedDict",
"ChatStreamCompletionCreateParamsSort",
"ChatStreamCompletionCreateParamsStop",
"ChatStreamCompletionCreateParamsStopTypedDict",
"ChatStreamCompletionCreateParamsStreamOptions",
"ChatStreamCompletionCreateParamsStreamOptionsTypedDict",
"ChatStreamCompletionCreateParamsTypeGrammar",
"ChatStreamCompletionCreateParamsTypeJSONObject",
"ChatStreamCompletionCreateParamsTypeJSONSchema",
"ChatStreamCompletionCreateParamsTypePython",
"ChatStreamCompletionCreateParamsTypeText",
"ChatStreamCompletionCreateParamsTypedDict",
"Completion",
"CompletionTokensDetails",
"CompletionTokensDetailsTypedDict",
"CompletionTypedDict",
"CompletionUsage",
"CompletionUsageTypedDict",
"ContentImageURL",
@@ -594,7 +387,12 @@ __all__ = [
"ContentTextTypedDict",
"ContentTypeImageURL",
"ContentTypeText",
"CreateChatCompletionResponse",
"CreateChatCompletionResponseTypedDict",
"DataCollection",
"Detail",
"Effort",
"Engine",
"Error",
"ErrorTypedDict",
"File",
@@ -605,12 +403,50 @@ __all__ = [
"FileAnnotationDetailImageURLTypedDict",
"FileAnnotationDetailTypedDict",
"FileTypedDict",
"IDChainOfThought",
"IDFileParser",
"IDModeration",
"IDWeb",
"Ignore",
"IgnoreEnum",
"IgnoreTypedDict",
"Image",
"ImageTypedDict",
"InputAudio",
"InputAudioTypedDict",
"JSONSchema",
"JSONSchemaTypedDict",
"MaxPrice",
"MaxPriceTypedDict",
"Only",
"OnlyEnum",
"OnlyTypedDict",
"Order",
"OrderEnum",
"OrderTypedDict",
"Parameters",
"ParametersTypedDict",
"Pdf",
"PdfEngine",
"PdfTypedDict",
"Plugin",
"PluginChainOfThought",
"PluginChainOfThoughtTypedDict",
"PluginFileParser",
"PluginFileParserTypedDict",
"PluginModeration",
"PluginModerationTypedDict",
"PluginTypedDict",
"PluginWeb",
"PluginWebTypedDict",
"Prompt",
"PromptTokensDetails",
"PromptTokensDetailsTypedDict",
"PromptTypedDict",
"Provider",
"ProviderTypedDict",
"Quantization",
"Reasoning",
"ReasoningDetail",
"ReasoningDetailEncrypted",
"ReasoningDetailEncryptedFormat",
@@ -625,15 +461,38 @@ __all__ = [
"ReasoningDetailTextType",
"ReasoningDetailTextTypedDict",
"ReasoningDetailTypedDict",
"ReasoningEffort",
"ReasoningTypedDict",
"Request",
"RequestTypedDict",
"ResponseFormat",
"ResponseFormatGrammar",
"ResponseFormatGrammarTypedDict",
"ResponseFormatJSONObject",
"ResponseFormatJSONObjectTypedDict",
"ResponseFormatJSONSchema",
"ResponseFormatJSONSchemaSchema",
"ResponseFormatJSONSchemaSchemaTypedDict",
"ResponseFormatJSONSchemaTypedDict",
"ResponseFormatPython",
"ResponseFormatPythonTypedDict",
"ResponseFormatText",
"ResponseFormatTextTypedDict",
"ResponseFormatTypedDict",
"Security",
"SecurityTypedDict",
"StreamChatCompletionResponseBody",
"StreamChatCompletionResponseBodyTypedDict",
"Sort",
"Stop",
"StopTypedDict",
"StreamOptions",
"StreamOptionsTypedDict",
"TopLogprob",
"TopLogprobTypedDict",
"TypeFile",
"TypeGrammar",
"TypeJSONObject",
"TypeJSONSchema",
"TypePython",
"URLCitation",
"URLCitationAnnotationDetail",
"URLCitationAnnotationDetailType",
@@ -669,6 +528,8 @@ _dynamic_imports: dict[str, str] = {
"ChatCompletionChunkChoiceDeltaToolCallFunctionTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
"ChatCompletionChunkChoiceDeltaToolCallType": ".chatcompletionchunkchoicedeltatoolcall",
"ChatCompletionChunkChoiceDeltaToolCallTypedDict": ".chatcompletionchunkchoicedeltatoolcall",
"ChatCompletionChunkWrapper": ".chatcompletionchunkwrapper",
"ChatCompletionChunkWrapperTypedDict": ".chatcompletionchunkwrapper",
"ChatCompletionContentPart": ".chatcompletioncontentpart",
"ChatCompletionContentPartTypedDict": ".chatcompletioncontentpart",
"ChatCompletionContentPartAudio": ".chatcompletioncontentpartaudio",
@@ -686,79 +547,79 @@ _dynamic_imports: dict[str, str] = {
"ChatCompletionContentPartText": ".chatcompletioncontentparttext",
"ChatCompletionContentPartTextType": ".chatcompletioncontentparttext",
"ChatCompletionContentPartTextTypedDict": ".chatcompletioncontentparttext",
"Audio": ".chatcompletioncreateparams",
"AudioTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParams": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsAudio": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsAudioTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsCompletion": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsCompletionTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsDataCollection": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsEffort": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsEngine": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsIDChainOfThought": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsIDFileParser": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsIDModeration": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsIDWeb": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsIgnoreEnum": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsIgnoreUnion": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsIgnoreUnionTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsImage": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsImageTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsJSONSchema": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsJSONSchemaTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsMaxPrice": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsMaxPriceTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsOnlyEnum": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsOnlyUnion": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsOnlyUnionTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsOrderEnum": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsOrderUnion": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsOrderUnionTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPdf": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPdfEngine": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPdfTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginChainOfThought": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginChainOfThoughtTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginFileParser": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginFileParserTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginModeration": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginModerationTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginUnion": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginUnionTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginWeb": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPluginWebTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPrompt": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsPromptTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsProvider": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsProviderTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsQuantization": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsReasoning": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsReasoningEffort": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsReasoningTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsRequest": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsRequestTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatGrammar": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatGrammarTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatJSONObject": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatJSONObjectTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatJSONSchema": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatJSONSchemaTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatPython": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatPythonTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatText": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatTextTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatUnion": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsResponseFormatUnionTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsSort": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsStop": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsStopTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsStreamOptions": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsStreamOptionsTypedDict": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsTypeGrammar": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsTypeJSONObject": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsTypeJSONSchema": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsTypePython": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsTypeText": ".chatcompletioncreateparams",
"ChatCompletionCreateParamsTypedDict": ".chatcompletioncreateparams",
"Completion": ".chatcompletioncreateparams",
"CompletionTypedDict": ".chatcompletioncreateparams",
"DataCollection": ".chatcompletioncreateparams",
"Effort": ".chatcompletioncreateparams",
"Engine": ".chatcompletioncreateparams",
"IDChainOfThought": ".chatcompletioncreateparams",
"IDFileParser": ".chatcompletioncreateparams",
"IDModeration": ".chatcompletioncreateparams",
"IDWeb": ".chatcompletioncreateparams",
"Ignore": ".chatcompletioncreateparams",
"IgnoreEnum": ".chatcompletioncreateparams",
"IgnoreTypedDict": ".chatcompletioncreateparams",
"Image": ".chatcompletioncreateparams",
"ImageTypedDict": ".chatcompletioncreateparams",
"JSONSchema": ".chatcompletioncreateparams",
"JSONSchemaTypedDict": ".chatcompletioncreateparams",
"MaxPrice": ".chatcompletioncreateparams",
"MaxPriceTypedDict": ".chatcompletioncreateparams",
"Only": ".chatcompletioncreateparams",
"OnlyEnum": ".chatcompletioncreateparams",
"OnlyTypedDict": ".chatcompletioncreateparams",
"Order": ".chatcompletioncreateparams",
"OrderEnum": ".chatcompletioncreateparams",
"OrderTypedDict": ".chatcompletioncreateparams",
"Pdf": ".chatcompletioncreateparams",
"PdfEngine": ".chatcompletioncreateparams",
"PdfTypedDict": ".chatcompletioncreateparams",
"Plugin": ".chatcompletioncreateparams",
"PluginChainOfThought": ".chatcompletioncreateparams",
"PluginChainOfThoughtTypedDict": ".chatcompletioncreateparams",
"PluginFileParser": ".chatcompletioncreateparams",
"PluginFileParserTypedDict": ".chatcompletioncreateparams",
"PluginModeration": ".chatcompletioncreateparams",
"PluginModerationTypedDict": ".chatcompletioncreateparams",
"PluginTypedDict": ".chatcompletioncreateparams",
"PluginWeb": ".chatcompletioncreateparams",
"PluginWebTypedDict": ".chatcompletioncreateparams",
"Prompt": ".chatcompletioncreateparams",
"PromptTypedDict": ".chatcompletioncreateparams",
"Provider": ".chatcompletioncreateparams",
"ProviderTypedDict": ".chatcompletioncreateparams",
"Quantization": ".chatcompletioncreateparams",
"Reasoning": ".chatcompletioncreateparams",
"ReasoningEffort": ".chatcompletioncreateparams",
"ReasoningTypedDict": ".chatcompletioncreateparams",
"Request": ".chatcompletioncreateparams",
"RequestTypedDict": ".chatcompletioncreateparams",
"ResponseFormat": ".chatcompletioncreateparams",
"ResponseFormatGrammar": ".chatcompletioncreateparams",
"ResponseFormatGrammarTypedDict": ".chatcompletioncreateparams",
"ResponseFormatJSONObject": ".chatcompletioncreateparams",
"ResponseFormatJSONObjectTypedDict": ".chatcompletioncreateparams",
"ResponseFormatJSONSchema": ".chatcompletioncreateparams",
"ResponseFormatJSONSchemaTypedDict": ".chatcompletioncreateparams",
"ResponseFormatPython": ".chatcompletioncreateparams",
"ResponseFormatPythonTypedDict": ".chatcompletioncreateparams",
"ResponseFormatText": ".chatcompletioncreateparams",
"ResponseFormatTextTypedDict": ".chatcompletioncreateparams",
"ResponseFormatTypedDict": ".chatcompletioncreateparams",
"Sort": ".chatcompletioncreateparams",
"Stop": ".chatcompletioncreateparams",
"StopTypedDict": ".chatcompletioncreateparams",
"StreamOptions": ".chatcompletioncreateparams",
"StreamOptionsTypedDict": ".chatcompletioncreateparams",
"TypeGrammar": ".chatcompletioncreateparams",
"TypeJSONObject": ".chatcompletioncreateparams",
"TypeJSONSchema": ".chatcompletioncreateparams",
"TypePython": ".chatcompletioncreateparams",
"Error": ".chatcompletionerror",
"ErrorTypedDict": ".chatcompletionerror",
"ChatCompletionMessage": ".chatcompletionmessage",
@@ -809,85 +670,14 @@ _dynamic_imports: dict[str, str] = {
"ChatCompletionUserMessageParamContentTypedDict": ".chatcompletionusermessageparam",
"ChatCompletionUserMessageParamRole": ".chatcompletionusermessageparam",
"ChatCompletionUserMessageParamTypedDict": ".chatcompletionusermessageparam",
"ChatStreamCompletionCreateParams": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsAudio": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsAudioTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsCompletion": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsCompletionTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsDataCollection": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsEffort": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsEngine": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsIDChainOfThought": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsIDFileParser": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsIDModeration": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsIDWeb": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsIgnoreEnum": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsIgnoreUnion": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsIgnoreUnionTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsImage": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsImageTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsJSONSchema": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsJSONSchemaTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsMaxPrice": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsMaxPriceTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsOnlyEnum": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsOnlyUnion": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsOnlyUnionTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsOrderEnum": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsOrderUnion": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsOrderUnionTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPdf": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPdfEngine": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPdfTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginChainOfThought": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginChainOfThoughtTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginFileParser": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginFileParserTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginModeration": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginModerationTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginUnion": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginUnionTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginWeb": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPluginWebTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPrompt": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsPromptTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsProvider": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsProviderTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsQuantization": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsReasoning": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsReasoningEffort": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsReasoningTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsRequest": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsRequestTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatGrammar": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatGrammarTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatJSONObject": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatJSONObjectTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatJSONSchema": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatJSONSchemaTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatPython": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatPythonTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatText": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatTextTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatUnion": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsResponseFormatUnionTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsSort": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsStop": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsStopTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsStreamOptions": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsStreamOptionsTypedDict": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsTypeGrammar": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsTypeJSONObject": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsTypeJSONSchema": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsTypePython": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsTypeText": ".chatstreamcompletioncreateparams",
"ChatStreamCompletionCreateParamsTypedDict": ".chatstreamcompletioncreateparams",
"CompletionTokensDetails": ".completionusage",
"CompletionTokensDetailsTypedDict": ".completionusage",
"CompletionUsage": ".completionusage",
"CompletionUsageTypedDict": ".completionusage",
"PromptTokensDetails": ".completionusage",
"PromptTokensDetailsTypedDict": ".completionusage",
"CreateChatCompletionResponse": ".createchatcompletionop",
"CreateChatCompletionResponseTypedDict": ".createchatcompletionop",
"ContentImageURL": ".fileannotationdetail",
"ContentImageURLTypedDict": ".fileannotationdetail",
"ContentText": ".fileannotationdetail",
@@ -921,8 +711,6 @@ _dynamic_imports: dict[str, str] = {
"ResponseFormatJSONSchemaSchemaTypedDict": ".responseformatjsonschemaschema",
"Security": ".security",
"SecurityTypedDict": ".security",
"StreamChatCompletionResponseBody": ".streamchatcompletionop",
"StreamChatCompletionResponseBodyTypedDict": ".streamchatcompletionop",
"URLCitation": ".urlcitationannotationdetail",
"URLCitationAnnotationDetail": ".urlcitationannotationdetail",
"URLCitationAnnotationDetailType": ".urlcitationannotationdetail",
@@ -931,6 +719,18 @@ _dynamic_imports: dict[str, str] = {
}
def dynamic_import(modname, retries=3):
for attempt in range(retries):
try:
return import_module(modname, __package__)
except KeyError:
# Clear any half-initialized module and retry
sys.modules.pop(modname, None)
if attempt == retries - 1:
break
raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
def __getattr__(attr_name: str) -> object:
module_name = _dynamic_imports.get(attr_name)
if module_name is None:
@@ -939,7 +739,7 @@ def __getattr__(attr_name: str) -> object:
)
try:
module = import_module(module_name, __package__)
module = dynamic_import(module_name)
result = getattr(module, attr_name)
return result
except ImportError as e:
+2 -4
View File
@@ -3,7 +3,6 @@
from __future__ import annotations
from .chatcompletionchoice import ChatCompletionChoice, ChatCompletionChoiceTypedDict
from .completionusage import CompletionUsage, CompletionUsageTypedDict
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -12,12 +11,11 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Optional
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict
class ChatCompletionObject(str, Enum):
CHAT_COMPLETION = "chat.completion"
ChatCompletionObject = Literal["chat.completion"]
class ChatCompletionTypedDict(TypedDict):
@@ -9,7 +9,6 @@ from .chatcompletionmessagetoolcall import (
ChatCompletionMessageToolCall,
ChatCompletionMessageToolCallTypedDict,
)
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -18,13 +17,11 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Any, List, Optional, Union
from typing import Any, List, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict
class ChatCompletionAssistantMessageParamRole(str, Enum):
ASSISTANT = "assistant"
ChatCompletionAssistantMessageParamRole = Literal["assistant"]
ChatCompletionAssistantMessageParamContentTypedDict = TypeAliasType(
"ChatCompletionAssistantMessageParamContentTypedDict",
@@ -6,7 +6,6 @@ from .chatcompletiontokenlogprobs import (
ChatCompletionTokenLogprobs,
ChatCompletionTokenLogprobsTypedDict,
)
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -15,17 +14,14 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Literal
from typing_extensions import NotRequired, TypedDict
class ChatCompletionChoiceFinishReason(str, Enum):
r"""Reason the completion finished"""
TOOL_CALLS = "tool_calls"
STOP = "stop"
LENGTH = "length"
CONTENT_FILTER = "content_filter"
ERROR = "error"
ChatCompletionChoiceFinishReason = Literal[
"tool_calls", "stop", "length", "content_filter", "error"
]
r"""Reason the completion finished"""
class ChatCompletionChoiceTypedDict(TypedDict):
+2 -4
View File
@@ -6,7 +6,6 @@ from .chatcompletionchunkchoice import (
ChatCompletionChunkChoiceTypedDict,
)
from .completionusage import CompletionUsage, CompletionUsageTypedDict
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -15,12 +14,11 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Optional
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict
class ChatCompletionChunkObject(str, Enum):
CHAT_COMPLETION_CHUNK = "chat.completion.chunk"
ChatCompletionChunkObject = Literal["chat.completion.chunk"]
class ChatCompletionChunkTypedDict(TypedDict):
@@ -9,7 +9,6 @@ from .chatcompletiontokenlogprobs import (
ChatCompletionTokenLogprobs,
ChatCompletionTokenLogprobsTypedDict,
)
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -18,15 +17,13 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Literal
from typing_extensions import NotRequired, TypedDict
class ChatCompletionChunkChoiceFinishReason(str, Enum):
TOOL_CALLS = "tool_calls"
STOP = "stop"
LENGTH = "length"
CONTENT_FILTER = "content_filter"
ERROR = "error"
ChatCompletionChunkChoiceFinishReason = Literal[
"tool_calls", "stop", "length", "content_filter", "error"
]
class ChatCompletionChunkChoiceTypedDict(TypedDict):
@@ -7,7 +7,6 @@ from .chatcompletionchunkchoicedeltatoolcall import (
ChatCompletionChunkChoiceDeltaToolCallTypedDict,
)
from .reasoningdetail import ReasoningDetail, ReasoningDetailTypedDict
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -16,14 +15,12 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Optional
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict
class ChatCompletionChunkChoiceDeltaRole(str, Enum):
r"""The role of the message author"""
ASSISTANT = "assistant"
ChatCompletionChunkChoiceDeltaRole = Literal["assistant"]
r"""The role of the message author"""
class ChatCompletionChunkChoiceDeltaTypedDict(TypedDict):
@@ -1,16 +1,13 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
from typing import Optional
from typing import Literal, Optional
from typing_extensions import NotRequired, TypedDict
class ChatCompletionChunkChoiceDeltaToolCallType(str, Enum):
r"""Tool call type"""
FUNCTION = "function"
ChatCompletionChunkChoiceDeltaToolCallType = Literal["function"]
r"""Tool call type"""
class ChatCompletionChunkChoiceDeltaToolCallFunctionTypedDict(TypedDict):
@@ -6,15 +6,11 @@ from openrouter.types import BaseModel
from typing_extensions import TypedDict
class StreamChatCompletionResponseBodyTypedDict(TypedDict):
r"""Successful chat completion response"""
class ChatCompletionChunkWrapperTypedDict(TypedDict):
data: ChatCompletionChunkTypedDict
r"""Streaming chat completion chunk"""
class StreamChatCompletionResponseBody(BaseModel):
r"""Successful chat completion response"""
class ChatCompletionChunkWrapper(BaseModel):
data: ChatCompletionChunk
r"""Streaming chat completion chunk"""
@@ -1,26 +1,18 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
import pydantic
from typing import Literal
from typing_extensions import Annotated, TypedDict
class ChatCompletionContentPartAudioType(str, Enum):
INPUT_AUDIO = "input_audio"
ChatCompletionContentPartAudioType = Literal["input_audio"]
class ChatCompletionContentPartAudioFormat(str, Enum):
r"""Audio format"""
WAV = "wav"
MP3 = "mp3"
FLAC = "flac"
M4A = "m4a"
OGG = "ogg"
PCM16 = "pcm16"
PCM24 = "pcm24"
ChatCompletionContentPartAudioFormat = Literal[
"wav", "mp3", "flac", "m4a", "ogg", "pcm16", "pcm24"
]
r"""Audio format"""
class InputAudioTypedDict(TypedDict):
@@ -1,22 +1,15 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
from typing import Optional
from typing import Literal, Optional
from typing_extensions import NotRequired, TypedDict
class ChatCompletionContentPartImageType(str, Enum):
IMAGE_URL = "image_url"
ChatCompletionContentPartImageType = Literal["image_url"]
class Detail(str, Enum):
r"""Image detail level for vision models"""
AUTO = "auto"
LOW = "low"
HIGH = "high"
Detail = Literal["auto", "low", "high"]
r"""Image detail level for vision models"""
class ChatCompletionContentPartImageImageURLTypedDict(TypedDict):
@@ -1,13 +1,12 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
from typing import Literal
from typing_extensions import TypedDict
class ChatCompletionContentPartTextType(str, Enum):
TEXT = "text"
ChatCompletionContentPartTextType = Literal["text"]
class ChatCompletionContentPartTextTypedDict(TypedDict):
File diff suppressed because it is too large Load Diff
+16 -9
View File
@@ -1,34 +1,41 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL
from openrouter.types import (
BaseModel,
Nullable,
OptionalNullable,
UNSET,
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing_extensions import TypedDict
from typing import Optional
from typing_extensions import NotRequired, TypedDict
class ErrorTypedDict(TypedDict):
r"""Error object structure"""
code: Nullable[str]
code: Nullable[float]
message: str
param: Nullable[str]
type: str
param: NotRequired[Nullable[str]]
type: NotRequired[str]
class Error(BaseModel):
r"""Error object structure"""
code: Nullable[str]
code: Nullable[float]
message: str
param: Nullable[str]
param: OptionalNullable[str] = UNSET
type: str
type: Optional[str] = None
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = []
optional_fields = ["param", "type"]
nullable_fields = ["code", "param"]
null_default_fields = []
@@ -7,7 +7,6 @@ from .chatcompletionmessagetoolcall import (
ChatCompletionMessageToolCallTypedDict,
)
from .reasoningdetail import ReasoningDetail, ReasoningDetailTypedDict
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -16,12 +15,11 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import List, Optional
from typing import List, Literal, Optional
from typing_extensions import NotRequired, TypedDict
class ChatCompletionMessageRole(str, Enum):
ASSISTANT = "assistant"
ChatCompletionMessageRole = Literal["assistant"]
class ChatCompletionMessageTypedDict(TypedDict):
@@ -1,13 +1,12 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
from typing import Literal
from typing_extensions import TypedDict
class ChatCompletionMessageToolCallType(str, Enum):
FUNCTION = "function"
ChatCompletionMessageToolCallType = Literal["function"]
class ChatCompletionMessageToolCallFunctionTypedDict(TypedDict):
@@ -1,13 +1,12 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
from typing import Literal
from typing_extensions import TypedDict
class ChatCompletionNamedToolChoiceType(str, Enum):
FUNCTION = "function"
ChatCompletionNamedToolChoiceType = Literal["function"]
class ChatCompletionNamedToolChoiceFunctionTypedDict(TypedDict):
@@ -5,15 +5,12 @@ from .chatcompletioncontentparttext import (
ChatCompletionContentPartText,
ChatCompletionContentPartTextTypedDict,
)
from enum import Enum
from openrouter.types import BaseModel
from typing import List, Optional, Union
from typing import List, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict
class ChatCompletionSystemMessageParamRole(str, Enum):
SYSTEM = "system"
ChatCompletionSystemMessageParamRole = Literal["system"]
ChatCompletionSystemMessageParamContentTypedDict = TypeAliasType(
"ChatCompletionSystemMessageParamContentTypedDict",
+2 -4
View File
@@ -1,7 +1,6 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -10,12 +9,11 @@ from openrouter.types import (
UNSET_SENTINEL,
)
from pydantic import model_serializer
from typing import Optional
from typing import Literal, Optional
from typing_extensions import NotRequired, TypedDict
class ChatCompletionToolType(str, Enum):
FUNCTION = "function"
ChatCompletionToolType = Literal["function"]
class ParametersTypedDict(TypedDict):
@@ -5,22 +5,15 @@ from .chatcompletionnamedtoolchoice import (
ChatCompletionNamedToolChoice,
ChatCompletionNamedToolChoiceTypedDict,
)
from enum import Enum
from typing import Union
from typing import Literal, Union
from typing_extensions import TypeAliasType
class ChatCompletionToolChoiceOptionRequired(str, Enum):
REQUIRED = "required"
ChatCompletionToolChoiceOptionRequired = Literal["required"]
ChatCompletionToolChoiceOptionAuto = Literal["auto"]
class ChatCompletionToolChoiceOptionAuto(str, Enum):
AUTO = "auto"
class ChatCompletionToolChoiceOptionNone(str, Enum):
NONE = "none"
ChatCompletionToolChoiceOptionNone = Literal["none"]
ChatCompletionToolChoiceOptionTypedDict = TypeAliasType(
"ChatCompletionToolChoiceOptionTypedDict",
@@ -5,15 +5,12 @@ from .chatcompletioncontentpart import (
ChatCompletionContentPart,
ChatCompletionContentPartTypedDict,
)
from enum import Enum
from openrouter.types import BaseModel
from typing import List, Union
from typing import List, Literal, Union
from typing_extensions import TypeAliasType, TypedDict
class ChatCompletionToolMessageParamRole(str, Enum):
TOOL = "tool"
ChatCompletionToolMessageParamRole = Literal["tool"]
ChatCompletionToolMessageParamContentTypedDict = TypeAliasType(
"ChatCompletionToolMessageParamContentTypedDict",
@@ -5,15 +5,12 @@ from .chatcompletioncontentpart import (
ChatCompletionContentPart,
ChatCompletionContentPartTypedDict,
)
from enum import Enum
from openrouter.types import BaseModel
from typing import List, Optional, Union
from typing import List, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict
class ChatCompletionUserMessageParamRole(str, Enum):
USER = "user"
ChatCompletionUserMessageParamRole = Literal["user"]
ChatCompletionUserMessageParamContentTypedDict = TypeAliasType(
"ChatCompletionUserMessageParamContentTypedDict",
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,35 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from .chatcompletion import ChatCompletion, ChatCompletionTypedDict
from .chatcompletionchunkwrapper import (
ChatCompletionChunkWrapper,
ChatCompletionChunkWrapperTypedDict,
)
from openrouter.utils import eventstreaming
from typing import Union
from typing_extensions import TypeAliasType
CreateChatCompletionResponseTypedDict = TypeAliasType(
"CreateChatCompletionResponseTypedDict",
Union[
ChatCompletionTypedDict,
Union[
eventstreaming.EventStream[ChatCompletionChunkWrapperTypedDict],
eventstreaming.EventStreamAsync[ChatCompletionChunkWrapperTypedDict],
],
],
)
CreateChatCompletionResponse = TypeAliasType(
"CreateChatCompletionResponse",
Union[
ChatCompletion,
Union[
eventstreaming.EventStream[ChatCompletionChunkWrapper],
eventstreaming.EventStreamAsync[ChatCompletionChunkWrapper],
],
],
)
@@ -1,18 +1,14 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
from typing import List, Optional, Union
from typing import List, Literal, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict
class TypeFile(str, Enum):
FILE = "file"
TypeFile = Literal["file"]
class ContentTypeImageURL(str, Enum):
IMAGE_URL = "image_url"
ContentTypeImageURL = Literal["image_url"]
class FileAnnotationDetailImageURLTypedDict(TypedDict):
@@ -34,8 +30,7 @@ class ContentImageURL(BaseModel):
image_url: FileAnnotationDetailImageURL
class ContentTypeText(str, Enum):
TEXT = "text"
ContentTypeText = Literal["text"]
class ContentTextTypedDict(TypedDict):
@@ -1,7 +1,6 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -11,18 +10,15 @@ from openrouter.types import (
)
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict
class ReasoningDetailEncryptedType(str, Enum):
REASONING_ENCRYPTED = "reasoning.encrypted"
ReasoningDetailEncryptedType = Literal["reasoning.encrypted"]
class ReasoningDetailEncryptedFormat(str, Enum):
UNKNOWN = "unknown"
OPENAI_RESPONSES_V1 = "openai-responses-v1"
ANTHROPIC_CLAUDE_V1 = "anthropic-claude-v1"
ReasoningDetailEncryptedFormat = Literal[
"unknown", "openai-responses-v1", "anthropic-claude-v1"
]
class ReasoningDetailEncryptedTypedDict(TypedDict):
@@ -46,7 +42,7 @@ class ReasoningDetailEncrypted(BaseModel):
format_: Annotated[
OptionalNullable[ReasoningDetailEncryptedFormat], pydantic.Field(alias="format")
] = ReasoningDetailEncryptedFormat.ANTHROPIC_CLAUDE_V1
] = "anthropic-claude-v1"
index: Optional[float] = None
@@ -1,7 +1,6 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -11,18 +10,15 @@ from openrouter.types import (
)
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict
class ReasoningDetailSummaryType(str, Enum):
REASONING_SUMMARY = "reasoning.summary"
ReasoningDetailSummaryType = Literal["reasoning.summary"]
class ReasoningDetailSummaryFormat(str, Enum):
UNKNOWN = "unknown"
OPENAI_RESPONSES_V1 = "openai-responses-v1"
ANTHROPIC_CLAUDE_V1 = "anthropic-claude-v1"
ReasoningDetailSummaryFormat = Literal[
"unknown", "openai-responses-v1", "anthropic-claude-v1"
]
class ReasoningDetailSummaryTypedDict(TypedDict):
@@ -46,7 +42,7 @@ class ReasoningDetailSummary(BaseModel):
format_: Annotated[
OptionalNullable[ReasoningDetailSummaryFormat], pydantic.Field(alias="format")
] = ReasoningDetailSummaryFormat.ANTHROPIC_CLAUDE_V1
] = "anthropic-claude-v1"
index: Optional[float] = None
+6 -10
View File
@@ -1,7 +1,6 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import (
BaseModel,
Nullable,
@@ -11,18 +10,15 @@ from openrouter.types import (
)
import pydantic
from pydantic import model_serializer
from typing import Optional
from typing import Literal, Optional
from typing_extensions import Annotated, NotRequired, TypedDict
class ReasoningDetailTextType(str, Enum):
REASONING_TEXT = "reasoning.text"
ReasoningDetailTextType = Literal["reasoning.text"]
class ReasoningDetailTextFormat(str, Enum):
UNKNOWN = "unknown"
OPENAI_RESPONSES_V1 = "openai-responses-v1"
ANTHROPIC_CLAUDE_V1 = "anthropic-claude-v1"
ReasoningDetailTextFormat = Literal[
"unknown", "openai-responses-v1", "anthropic-claude-v1"
]
class ReasoningDetailTextTypedDict(TypedDict):
@@ -49,7 +45,7 @@ class ReasoningDetailText(BaseModel):
format_: Annotated[
OptionalNullable[ReasoningDetailTextFormat], pydantic.Field(alias="format")
] = ReasoningDetailTextFormat.ANTHROPIC_CLAUDE_V1
] = "anthropic-claude-v1"
index: Optional[float] = None
+2 -2
View File
@@ -8,11 +8,11 @@ from typing_extensions import Annotated, NotRequired, TypedDict
class SecurityTypedDict(TypedDict):
bearer_auth: NotRequired[str]
api_key: NotRequired[str]
class Security(BaseModel):
bearer_auth: Annotated[
api_key: Annotated[
Optional[str],
FieldMetadata(
security=SecurityMetadata(
@@ -1,14 +1,12 @@
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from enum import Enum
from openrouter.types import BaseModel
from typing import Optional
from typing import Literal, Optional
from typing_extensions import NotRequired, TypedDict
class URLCitationAnnotationDetailType(str, Enum):
URL_CITATION = "url_citation"
URLCitationAnnotationDetailType = Literal["url_citation"]
class URLCitationTypedDict(TypedDict):
+20 -8
View File
@@ -10,6 +10,7 @@ import importlib
from openrouter import models, utils
from openrouter._hooks import SDKHooks
from openrouter.types import OptionalNullable, UNSET
import sys
from typing import Any, Callable, Dict, List, Optional, TYPE_CHECKING, Union, cast
import weakref
@@ -23,14 +24,13 @@ class OpenRouter(BaseSDK):
"""
chat: "Chat"
r"""Chat completion operations"""
_sub_sdk_map = {
"chat": ("openrouter.chat", "Chat"),
}
def __init__(
self,
bearer_auth: Optional[Union[Optional[str], Callable[[], Optional[str]]]] = None,
api_key: Optional[Union[Optional[str], Callable[[], Optional[str]]]] = None,
provider_url: Optional[str] = None,
server_idx: Optional[int] = None,
server_url: Optional[str] = None,
@@ -43,7 +43,7 @@ class OpenRouter(BaseSDK):
) -> None:
r"""Instantiates the SDK configuring it with the provided parameters.
:param bearer_auth: The bearer_auth required for authentication
:param api_key: The api_key required for authentication
:param provider_url: Allows setting the provider_url variable for url substitution
:param server_idx: The index of the server to use for all methods
:param server_url: The server URL to use for all methods
@@ -75,11 +75,11 @@ class OpenRouter(BaseSDK):
), "The provided async_client must implement the AsyncHttpClient protocol."
security: Any = None
if callable(bearer_auth):
if callable(api_key):
# pylint: disable=unnecessary-lambda-assignment
security = lambda: models.Security(bearer_auth=bearer_auth())
security = lambda: models.Security(api_key=api_key())
else:
security = models.Security(bearer_auth=bearer_auth)
security = models.Security(api_key=api_key)
if server_url is not None:
if url_params is not None:
@@ -105,6 +105,7 @@ class OpenRouter(BaseSDK):
timeout_ms=timeout_ms,
debug_logger=debug_logger,
),
parent_ref=self,
)
hooks = SDKHooks()
@@ -124,13 +125,24 @@ class OpenRouter(BaseSDK):
self.sdk_configuration.async_client_supplied,
)
def dynamic_import(self, modname, retries=3):
for attempt in range(retries):
try:
return importlib.import_module(modname)
except KeyError:
# Clear any half-initialized module and retry
sys.modules.pop(modname, None)
if attempt == retries - 1:
break
raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
def __getattr__(self, name: str):
if name in self._sub_sdk_map:
module_path, class_name = self._sub_sdk_map[name]
try:
module = importlib.import_module(module_path)
module = self.dynamic_import(module_path)
klass = getattr(module, class_name)
instance = klass(self.sdk_configuration)
instance = klass(self.sdk_configuration, parent_ref=self)
setattr(self, name, instance)
return instance
except ImportError as e:
+15 -3
View File
@@ -3,6 +3,7 @@
from typing import TYPE_CHECKING
from importlib import import_module
import builtins
import sys
if TYPE_CHECKING:
from .annotations import get_discriminator
@@ -162,6 +163,18 @@ _dynamic_imports: dict[str, str] = {
}
def dynamic_import(modname, retries=3):
for attempt in range(retries):
try:
return import_module(modname, __package__)
except KeyError:
# Clear any half-initialized module and retry
sys.modules.pop(modname, None)
if attempt == retries - 1:
break
raise KeyError(f"Failed to import module '{modname}' after {retries} attempts")
def __getattr__(attr_name: str) -> object:
module_name = _dynamic_imports.get(attr_name)
if module_name is None:
@@ -170,9 +183,8 @@ def __getattr__(attr_name: str) -> object:
)
try:
module = import_module(module_name, __package__)
result = getattr(module, attr_name)
return result
module = dynamic_import(module_name)
return getattr(module, attr_name)
except ImportError as e:
raise ImportError(
f"Failed to import {attr_name} from {module_name}: {e}"
+10
View File
@@ -17,6 +17,9 @@ T = TypeVar("T")
class EventStream(Generic[T]):
# Holds a reference to the SDK client to avoid it being garbage collected
# and cause termination of the underlying httpx client.
client_ref: Optional[object]
response: httpx.Response
generator: Generator[T, None, None]
@@ -25,9 +28,11 @@ class EventStream(Generic[T]):
response: httpx.Response,
decoder: Callable[[str], T],
sentinel: Optional[str] = None,
client_ref: Optional[object] = None,
):
self.response = response
self.generator = stream_events(response, decoder, sentinel)
self.client_ref = client_ref
def __iter__(self):
return self
@@ -43,6 +48,9 @@ class EventStream(Generic[T]):
class EventStreamAsync(Generic[T]):
# Holds a reference to the SDK client to avoid it being garbage collected
# and cause termination of the underlying httpx client.
client_ref: Optional[object]
response: httpx.Response
generator: AsyncGenerator[T, None]
@@ -51,9 +59,11 @@ class EventStreamAsync(Generic[T]):
response: httpx.Response,
decoder: Callable[[str], T],
sentinel: Optional[str] = None,
client_ref: Optional[object] = None,
):
self.response = response
self.generator = stream_events_async(response, decoder, sentinel)
self.client_ref = client_ref
def __aiter__(self):
return self
+2 -2
View File
@@ -64,8 +64,8 @@ def get_security_from_env(security: Any, security_class: Any) -> Optional[BaseMo
security_dict: Any = {}
if os.getenv("OPENROUTER_BEARER_AUTH"):
security_dict["bearer_auth"] = os.getenv("OPENROUTER_BEARER_AUTH")
if os.getenv("OPENROUTER_API_KEY"):
security_dict["api_key"] = os.getenv("OPENROUTER_API_KEY")
return security_class(**security_dict) if security_dict else None