Files
openrouter-python-sdk-retry…/src/openrouter/operations/getgeneration.py
T
OpenRouter Team 82bbe75d87 Commits included in this export:
- 68922847c2969b773887310eb7aa9a814e199c5a
  - 729ee2338c39df22461526153e7f4ba868fd498e
  - e1074ff86fccf5e48406b7595298873106d3cc5a
  - 123bbdaf841d299162a82ee2573adfbb70a45b8f
  - ac457b8a8dad98fdf5ddcae8dd4711361cea3084
  - ea825199f4c59dd68fec01cf8d18a582963c9f25
  - 4d48e4f6bb936e785787314a965298da6b78fea0
  - 718729a573ee98893a4408d5a52ab4686661fe54
  - b867adcde6b64f3f2a11c4626254b39098e4b0b4
  - 21912c097b4066d109766c6b4492826595cd57c5
  - bc1ed85adc976a4634ca8a41b82e4fc2c39a864f
  - d145c89c941937a312ed1357590d2bfda9a3603d
  - 12f05b5dee397ead47cfcd545a7a2e3c7ff57524
  - dd28f75a19a015809797c7abf3f8758f7c37262e
  - c96e569781e07ab44172d9c69940ec17bafd81f4
  - c9d5a90e3c2b5077a2bdd49773f1a46d1a5a79c7
  - 58b08f87116ceab9076de2fdc0a4c74c919b44c4

GitOrigin-RevId: 68922847c2969b773887310eb7aa9a814e199c5a
2026-01-29 18:16:59 +00:00

453 lines
12 KiB
Python

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL, UnrecognizedStr
from openrouter.utils import FieldMetadata, QueryParamMetadata, validate_open_enum
from pydantic import model_serializer
from pydantic.functional_validators import PlainValidator
from typing import List, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict
class GetGenerationRequestTypedDict(TypedDict):
id: str
class GetGenerationRequest(BaseModel):
id: Annotated[
str, FieldMetadata(query=QueryParamMetadata(style="form", explode=True))
]
APIType = Union[
Literal[
"completions",
"embeddings",
],
UnrecognizedStr,
]
r"""Type of API used for the generation"""
ProviderName = Union[
Literal[
"AnyScale",
"Atoma",
"Cent-ML",
"CrofAI",
"Enfer",
"GoPomelo",
"HuggingFace",
"Hyperbolic 2",
"InoCloud",
"Kluster",
"Lambda",
"Lepton",
"Lynn 2",
"Lynn",
"Mancer",
"Meta",
"Modal",
"Nineteen",
"OctoAI",
"Recursal",
"Reflection",
"Replicate",
"SambaNova 2",
"SF Compute",
"Targon",
"Together 2",
"Ubicloud",
"01.AI",
"AI21",
"AionLabs",
"Alibaba",
"Ambient",
"Amazon Bedrock",
"Amazon Nova",
"Anthropic",
"Arcee AI",
"AtlasCloud",
"Avian",
"Azure",
"BaseTen",
"BytePlus",
"Black Forest Labs",
"Cerebras",
"Chutes",
"Cirrascale",
"Clarifai",
"Cloudflare",
"Cohere",
"Crusoe",
"DeepInfra",
"DeepSeek",
"Featherless",
"Fireworks",
"Friendli",
"GMICloud",
"Google",
"Google AI Studio",
"Groq",
"Hyperbolic",
"Inception",
"Inceptron",
"InferenceNet",
"Infermatic",
"Inflection",
"Liquid",
"Mara",
"Mancer 2",
"Minimax",
"ModelRun",
"Mistral",
"Modular",
"Moonshot AI",
"Morph",
"NCompass",
"Nebius",
"NextBit",
"Novita",
"Nvidia",
"OpenAI",
"OpenInference",
"Parasail",
"Perplexity",
"Phala",
"Relace",
"SambaNova",
"Seed",
"SiliconFlow",
"Sourceful",
"StepFun",
"Stealth",
"StreamLake",
"Switchpoint",
"Together",
"Upstage",
"Venice",
"WandB",
"Xiaomi",
"xAI",
"Z.AI",
"FakeProvider",
],
UnrecognizedStr,
]
class ProviderResponseTypedDict(TypedDict):
status: Nullable[float]
id: NotRequired[str]
endpoint_id: NotRequired[str]
model_permaslug: NotRequired[str]
provider_name: NotRequired[ProviderName]
latency: NotRequired[float]
is_byok: NotRequired[bool]
class ProviderResponse(BaseModel):
status: Nullable[float]
id: Optional[str] = None
endpoint_id: Optional[str] = None
model_permaslug: Optional[str] = None
provider_name: Annotated[
Optional[ProviderName], PlainValidator(validate_open_enum(False))
] = None
latency: Optional[float] = None
is_byok: Optional[bool] = None
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = [
"id",
"endpoint_id",
"model_permaslug",
"provider_name",
"latency",
"is_byok",
]
nullable_fields = ["status"]
null_default_fields = []
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k)
serialized.pop(k, None)
optional_nullable = k in optional_fields and k in nullable_fields
is_set = (
self.__pydantic_fields_set__.intersection({n})
or k in null_default_fields
) # pylint: disable=no-member
if val is not None and val != UNSET_SENTINEL:
m[k] = val
elif val != UNSET_SENTINEL and (
not k in optional_fields or (optional_nullable and is_set)
):
m[k] = val
return m
class GetGenerationDataTypedDict(TypedDict):
r"""Generation data"""
id: str
r"""Unique identifier for the generation"""
upstream_id: Nullable[str]
r"""Upstream provider's identifier for this generation"""
total_cost: float
r"""Total cost of the generation in USD"""
cache_discount: Nullable[float]
r"""Discount applied due to caching"""
upstream_inference_cost: Nullable[float]
r"""Cost charged by the upstream provider"""
created_at: str
r"""ISO 8601 timestamp of when the generation was created"""
model: str
r"""Model used for the generation"""
app_id: Nullable[float]
r"""ID of the app that made the request"""
streamed: Nullable[bool]
r"""Whether the response was streamed"""
cancelled: Nullable[bool]
r"""Whether the generation was cancelled"""
provider_name: Nullable[str]
r"""Name of the provider that served the request"""
latency: Nullable[float]
r"""Total latency in milliseconds"""
moderation_latency: Nullable[float]
r"""Moderation latency in milliseconds"""
generation_time: Nullable[float]
r"""Time taken for generation in milliseconds"""
finish_reason: Nullable[str]
r"""Reason the generation finished"""
tokens_prompt: Nullable[float]
r"""Number of tokens in the prompt"""
tokens_completion: Nullable[float]
r"""Number of tokens in the completion"""
native_tokens_prompt: Nullable[float]
r"""Native prompt tokens as reported by provider"""
native_tokens_completion: Nullable[float]
r"""Native completion tokens as reported by provider"""
native_tokens_completion_images: Nullable[float]
r"""Native completion image tokens as reported by provider"""
native_tokens_reasoning: Nullable[float]
r"""Native reasoning tokens as reported by provider"""
native_tokens_cached: Nullable[float]
r"""Native cached tokens as reported by provider"""
num_media_prompt: Nullable[float]
r"""Number of media items in the prompt"""
num_input_audio_prompt: Nullable[float]
r"""Number of audio inputs in the prompt"""
num_media_completion: Nullable[float]
r"""Number of media items in the completion"""
num_search_results: Nullable[float]
r"""Number of search results included"""
origin: str
r"""Origin URL of the request"""
usage: float
r"""Usage amount in USD"""
is_byok: bool
r"""Whether this used bring-your-own-key"""
native_finish_reason: Nullable[str]
r"""Native finish reason as reported by provider"""
external_user: Nullable[str]
r"""External user identifier"""
api_type: Nullable[APIType]
r"""Type of API used for the generation"""
router: Nullable[str]
r"""Router used for the request (e.g., openrouter/auto)"""
provider_responses: Nullable[List[ProviderResponseTypedDict]]
r"""List of provider responses for this generation, including fallback attempts"""
class GetGenerationData(BaseModel):
r"""Generation data"""
id: str
r"""Unique identifier for the generation"""
upstream_id: Nullable[str]
r"""Upstream provider's identifier for this generation"""
total_cost: float
r"""Total cost of the generation in USD"""
cache_discount: Nullable[float]
r"""Discount applied due to caching"""
upstream_inference_cost: Nullable[float]
r"""Cost charged by the upstream provider"""
created_at: str
r"""ISO 8601 timestamp of when the generation was created"""
model: str
r"""Model used for the generation"""
app_id: Nullable[float]
r"""ID of the app that made the request"""
streamed: Nullable[bool]
r"""Whether the response was streamed"""
cancelled: Nullable[bool]
r"""Whether the generation was cancelled"""
provider_name: Nullable[str]
r"""Name of the provider that served the request"""
latency: Nullable[float]
r"""Total latency in milliseconds"""
moderation_latency: Nullable[float]
r"""Moderation latency in milliseconds"""
generation_time: Nullable[float]
r"""Time taken for generation in milliseconds"""
finish_reason: Nullable[str]
r"""Reason the generation finished"""
tokens_prompt: Nullable[float]
r"""Number of tokens in the prompt"""
tokens_completion: Nullable[float]
r"""Number of tokens in the completion"""
native_tokens_prompt: Nullable[float]
r"""Native prompt tokens as reported by provider"""
native_tokens_completion: Nullable[float]
r"""Native completion tokens as reported by provider"""
native_tokens_completion_images: Nullable[float]
r"""Native completion image tokens as reported by provider"""
native_tokens_reasoning: Nullable[float]
r"""Native reasoning tokens as reported by provider"""
native_tokens_cached: Nullable[float]
r"""Native cached tokens as reported by provider"""
num_media_prompt: Nullable[float]
r"""Number of media items in the prompt"""
num_input_audio_prompt: Nullable[float]
r"""Number of audio inputs in the prompt"""
num_media_completion: Nullable[float]
r"""Number of media items in the completion"""
num_search_results: Nullable[float]
r"""Number of search results included"""
origin: str
r"""Origin URL of the request"""
usage: float
r"""Usage amount in USD"""
is_byok: bool
r"""Whether this used bring-your-own-key"""
native_finish_reason: Nullable[str]
r"""Native finish reason as reported by provider"""
external_user: Nullable[str]
r"""External user identifier"""
api_type: Annotated[Nullable[APIType], PlainValidator(validate_open_enum(False))]
r"""Type of API used for the generation"""
router: Nullable[str]
r"""Router used for the request (e.g., openrouter/auto)"""
provider_responses: Nullable[List[ProviderResponse]]
r"""List of provider responses for this generation, including fallback attempts"""
@model_serializer(mode="wrap")
def serialize_model(self, handler):
optional_fields = []
nullable_fields = [
"upstream_id",
"cache_discount",
"upstream_inference_cost",
"app_id",
"streamed",
"cancelled",
"provider_name",
"latency",
"moderation_latency",
"generation_time",
"finish_reason",
"tokens_prompt",
"tokens_completion",
"native_tokens_prompt",
"native_tokens_completion",
"native_tokens_completion_images",
"native_tokens_reasoning",
"native_tokens_cached",
"num_media_prompt",
"num_input_audio_prompt",
"num_media_completion",
"num_search_results",
"native_finish_reason",
"external_user",
"api_type",
"router",
"provider_responses",
]
null_default_fields = []
serialized = handler(self)
m = {}
for n, f in type(self).model_fields.items():
k = f.alias or n
val = serialized.get(k)
serialized.pop(k, None)
optional_nullable = k in optional_fields and k in nullable_fields
is_set = (
self.__pydantic_fields_set__.intersection({n})
or k in null_default_fields
) # pylint: disable=no-member
if val is not None and val != UNSET_SENTINEL:
m[k] = val
elif val != UNSET_SENTINEL and (
not k in optional_fields or (optional_nullable and is_set)
):
m[k] = val
return m
class GetGenerationResponseTypedDict(TypedDict):
r"""Generation response"""
data: GetGenerationDataTypedDict
r"""Generation data"""
class GetGenerationResponse(BaseModel):
r"""Generation response"""
data: GetGenerationData
r"""Generation data"""