OpenRouterClient class
Client for interacting with the OpenRouter API.
Inherits OpenAI-compatible behavior but adds OpenRouter-specific headers for site attribution and rankings.
- Implemented types
Constructors
- OpenRouterClient({required String apiKey, required String model, String? siteUrl, String? siteName, double? temperature, int? maxCompletionTokens, double? topP, String? reasoningEffort, dynamic stop, void onRetry(int attempt, Duration nextDelay, dynamic error)?, Client? httpClient})
- Creates an OpenRouterClient with the specified configuration.
Properties
- apiKey → String
-
API key for authentication.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- maxCompletionTokens → int?
-
Default maximum completion tokens.
final
- model → String
-
Default model to use for requests.
final
- onRetry → void Function(int attempt, Duration nextDelay, dynamic error)?
-
Callback emitted when a request is about to be retried.
final
- reasoningEffort → String?
-
Default reasoning effort.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- siteName → String?
-
Optional site name for OpenRouter rankings.
final
- siteUrl → String?
-
Optional site URL for OpenRouter rankings.
final
- stop → dynamic
-
Default stop sequences.
final
- temperature → double?
-
Default temperature for responses.
final
- topP → double?
-
Default top-p sampling parameter.
final
Methods
-
close(
) → void -
Closes the client and cleans up any resources.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
sendChatRequest(
List< Map< messages, List<String, dynamic> >Map< ? tools, {double? temperature, int? maxCompletionTokens, double? topP, bool? stream, String? reasoningEffort, dynamic stop, CancellationToken? cancellationToken}) → Future<String, dynamic> >Map< String, dynamic> > -
Sends a single, complete chat request to the LLM.
override
-
sendStreamingChatRequest(
List< Map< messages, List<String, dynamic> >Map< ? tools, {double? temperature, int? maxCompletionTokens, double? topP, String? reasoningEffort, dynamic stop, CancellationToken? cancellationToken}) → Stream<String, dynamic> >Map< String, dynamic> > -
Sends a streaming chat request to the LLM, yielding chunks as they arrive.
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited