openrouter_sdk library

Classes

AdvisorTool
Consults a higher-intelligence advisor model mid-generation for guidance.
AnalyticsResource
Analytics resource
ApiKey
Represents an API key.
ApiKeyMetadata
ApiKeysResource
Api keys resource
AssistantMessage
Assistant message.
AudioContent
Audio content part.
BashTool
Runs shell commands via the OpenRouter bash tool.
ChatMessage
Base class for a chat message.
ChatResource
Chat resource
ChatResponse
Chat response.
ChatResponseUsage
Chat response usage.
CreditsResource
Credits resource
CustomTool
A user-defined tool with a custom type and parameters.
DatetimeTool
Provides the current date and time to the model.
DeveloperMessage
Developer message.
Endpoint
Endpoint information.
EndpointsResource
Endpoints resource
FileContent
File content part.
FunctionTool
GenerationsResource
Generations resource
ImageContent
Image content part.
ImageGenerationConfig
Configuration for image generation requests.
ImageGenerationTool
MessageContent
Base class for message content parts.
Model
LLM model.
ModelsResource
Models resource
OpenRouter
Main class for interacting with OpenRouter API
OpenRouterMetadata
Openrouter metadata.
OpenRouterServerTool
base class type for tools provided and executed by the openrouter server
Plugin
A plugin that extends model behavior for a request (e.g. web search, auto-routing).
ProviderSettings
Provider settings.
ProvidersResource
Providers resource
ReasoningDetail
A single detail emitted as part of a model's reasoning output.
Resource
Base class for API resources that wrap an OpenRouter client.
ResponseFormat
Controls the format of the model's response output.
ServerToolsStopCondition
A condition that stops an agent loop when it is met.
SubagentTool
SystemMessage
System message.
TextContent
Text content part.
Tool
base class type for all tools
ToolChoiceConfig
Configures how the model selects which tool (if any) to call.
ToolMessage
Tool message.
UserMessage
User message.
VideoContent
Video content part.
WebFetchTool
WebSearchTool

Enums

ApiType
Type of API used for a generation
AspectRatio
Aspect ratio for image generation.
BackgroundStyle
background style for image generation.
CacheControlTTL
controls prompt caching time to live.
Country
List of countries.
DataRegion
EndpointStatus
Endpoint status enum as defined in the OpenRouter API
FinishReason
Finish reason
ImageDetail
ImageFormat
ImageQuality
ImageResolution
InstructType
LimitResetCycle
Modality
ModelCategory
ModelParameter
ModelSort
OpenRouterErrorType
PdfEngine
PipelineType
Preset
Provider
Providers offered by OpenRouter.
ProviderSort
ProviderSortPartition
Quantization
ReasoningEffort
ReasoningFormat
ReasoningSummary
Region
RoutingStrategy
SearchContextSize
ServiceTier
Tokenizer
WebFetchEngine
WebSearchEngine

Typedefs

Activity = ({double byokUsageInference, int completionTokens, DateTime date, String endpointId, String model, String modelPermaslug, int promptTokens, String provider, int reasoningTokens, int requests, double usage})
Activity statistics.
ArtificialAnalysisBenchmark = ({double? agenticIndex, double? codingIndex, double? intelligenceIndex})
Artificial Analysis benchmark index scores.
Credits = ({double totalCredits, double totalUsage})
Credits information.
DesignArenaBenchmark = ({String arena, String category, double elo, int rank, double winRate})
Design Arena benchmark index scores.
EndpointData = ({ModelArchitecture architecture, DateTime createdAt, String description, List<Endpoint> endpoints, String id, String name})
Endpoint data
EndpointInfo = ({String model, String provider, bool selected})
Endpoint information.
EndpointsMedatada = ({List<EndpointInfo> available, int total})
Endpoints metadata.
Generation = ({ApiType apiType, int? appId, double cacheDiscount, bool cancelled, int completionMedias, int completionTokens, DateTime createdAt, DataRegion dataRegion, String? externalUserId, FinishReason? finishReason, Duration? generationTime, String? httpReferer, String id, bool isByok, Duration? latency, String model, Duration? moderationLatency, int nativeCachedTokens, int nativeCompletionTokens, String? nativeFinishReason, int nativeImagesCompletionTokens, int nativePromptTokens, int nativeReasoningTokens, String origin, String? presetId, int promptAudioInputs, int promptMedias, int promptTokens, Provider providerName, List<ProviderResponse> providerResponses, String? requestId, String? responseCacheSourceId, String? router, int searchResults, ServiceTier serviceTier, String? sessionId, bool streamed, double totalCost, String? upstreamId, double? upstreamInferenceCost, double usage, String? userAgent, int webFetches, String? webSearchEngine})
Generation information.
LatencyLast30Minutes = ({double p50, double p75, double p90, double p99})
Latency percentiles in milliseconds.
LogProb = ({Uint8List? bytes, double logProb, String token, List<_LogProb> topLogProbs})
Log probability information.
ModelArchitecture = ({List<Modality> inputModalities, InstructType? instructType, String? modality, List<Modality> outputModalities, Tokenizer tokenizer})
Model architecture information
ModelBenchmarks = ({ArtificialAnalysisBenchmark? artificialAnalysis, List<DesignArenaBenchmark> designArena})
Model benchmark information
ModelParameters = ({double? frequencyPenalty, double? presencePenalty, double? repetitionPenalty, double? temperature, int? topK, double? topP})
Model parameters
ModelPricing = ({double audio, double audioOutput, double completion, double discount, double image, double imageOutput, double imageToken, double inputAudioCache, double inputCacheRead, double inputCacheWrite, double inputCacheWrite1h, double internalReasoning, double prompt, double request, double webSearch})
Model pricing information
ModelReasoning = ({ReasoningEffort defaultEffort, bool? defaultEnabled, bool isMandatory, List<ReasoningEffort> supportedEfforts, bool? supportsMaxTokens})
Model reasoning configuration
ModelTopProvider = ({int contextLength, bool isModerated, int maxCompletionTokens})
Model top provider information
PipelineStage = ({double cost, Map<String, dynamic> data, String? guardrailId, String? guardrailScope, String name, String? summary, PipelineType type})
Pipeline stage information.
ProviderData = ({List<Country> dataCenters, Country headquarters, String name, String privacyPolicyUrl, String slug, String? statusPageUrl, String? termsOfServiceUrl})
Provider information.
ProviderResponse = ({String? endpointId, String? id, bool? isByok, Duration? latency, String? modelPermaslug, Provider providerName, int? statusCode})
Provider response information.
ResponseChoice = ({FinishReason? finishReason, int index, ({List<LogProb> content, List<LogProb> refusal}) logProbs, AssistantMessage message})
Response choice information.
ThroughputLast30Minutes = ({double p50, double p75, double p90, double p99})
Throughput percentiles in tokens per second.
ToolCall = ({dynamic arguments, String funcitonName, String id, int index})
Function call details

Exceptions / Errors

OpenRouterException
openrouter exception