OpenRouterProvider class

Streams chat completions from OpenRouter, whose API mirrors OpenAI's /chat/completions schema and proxies models from Anthropic, OpenAI, Google, Meta and others behind one key.

Inheritance

Constructors

OpenRouterProvider({required String apiKey, required String model, Client? httpClient, Uri? endpoint, List<Map<String, Object?>>? tools, Map<String, Object?>? extraParams})
Creates an OpenRouter provider.

Properties

apiKey String
Your OpenRouter API key.
final
extraParams Map<String, Object?>?
Extra body fields merged in, e.g. {'temperature': 0.7}.
final
hashCode int
The hash code for this object.
no setterinherited
model String
Model id, e.g. anthropic/claude-sonnet-4.5 or openai/gpt-4o.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tools List<Map<String, Object?>>?
Raw OpenAI-shaped function/tool schemas, passed through as tools in the request body. null omits the field.
final

Methods

asResponder({List<ChatMessage> history()?}) AgentResponder
Adapts this provider to AgentResponder, for ChatController's managed send().
inherited
dispose() → void
Releases resources held by this provider.
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
sendMessage(ChatController controller, String text, {List<Attachment>? attachments}) Future<void>
Drives controller's manual streaming API directly, so tool calls surface as ToolCalls instead of being dropped.
inherited
streamEvents(List<ChatMessage> conversation) Stream<ProviderEvent>
Streams structured events for conversation's next assistant turn.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited