Package com.tnsai.llm.providers
Class OpenRouterClient
java.lang.Object
com.tnsai.llm.providers.AbstractLLMClient
com.tnsai.llm.providers.AbstractOpenAICompatibleClient
com.tnsai.llm.providers.OpenRouterClient
- All Implemented Interfaces:
com.tnsai.llm.LLMClient
OpenRouter LLM client implementation.
Provides unified access to 300+ models from 60+ providers via OpenRouter's API.
OpenRouter speaks the OpenAI /chat/completions wire format, so this
client is a thin subclass of AbstractOpenAICompatibleClient; its only
divergence is a set of optional ranking / routing headers attached via
addProviderHeaders(Request.Builder).
Model naming convention: "provider/model-name"
- openai/gpt-4o - OpenAI GPT-4o
- anthropic/claude-3.5-sonnet - Anthropic Claude 3.5 Sonnet
- google/gemini-pro-1.5 - Google Gemini Pro 1.5
Configuration via environment variables:
- OPENROUTER_API_KEY - Required API key for authentication
- OPENROUTER_SITE_URL - Optional, your site URL for ranking
- OPENROUTER_SITE_NAME - Optional, your site name for ranking
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBeta header that opts into Anthropic's fine-grained tool streaming. -
Constructor Summary
ConstructorsConstructorDescriptionOpenRouterClient(String model) OpenRouterClient(String model, float temperature) OpenRouterClient(String model, float temperature, Float topP, Integer maxTokens) OpenRouterClient(String model, float temperature, Float topP, Integer maxTokens, String apiKey, String siteUrl, String siteName) OpenRouterClient(String model, float temperature, Integer maxTokens) OpenRouterClient(String model, float temperature, Integer maxTokens, String apiKey, String siteUrl, String siteName) -
Method Summary
Modifier and TypeMethodDescriptionbooleanWhether the fine-grained tool streaming beta header will be sent (#26).setFineGrainedToolStreaming(boolean enabled) Explicit override for the auto-detected fine-grained tool streaming flag (#26).Methods inherited from class com.tnsai.llm.providers.AbstractOpenAICompatibleClient
chat, streamChatMethods inherited from class com.tnsai.llm.providers.AbstractLLMClient
getBaseUrl, getCallTimeoutMs, getMaxTokens, getModel, getTemperature, getTopPMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.llm.LLMClient
chat, chat, chat, chat, chat, getCapabilities, getProviderName, listModels, streamChat, streamChat, streamChatWithHandler, streamChatWithHandler, streamChatWithSpec, streamChatWithSpec
-
Field Details
-
BETA_FINE_GRAINED_TOOL_STREAMING
Beta header that opts into Anthropic's fine-grained tool streaming. Only meaningful when the underlying model is Claude — OpenRouter passes it through to Anthropic when routing to a Claude model.- Since:
- 0.5.0 (issue #26)
- See Also:
-
-
Constructor Details
-
OpenRouterClient
-
OpenRouterClient
-
OpenRouterClient
-
OpenRouterClient
-
OpenRouterClient
-
OpenRouterClient
-
-
Method Details
-
setFineGrainedToolStreaming
Explicit override for the auto-detected fine-grained tool streaming flag (#26). Returnsthisfor fluent configuration.Use to opt OUT on a Claude model (you've measured it makes things worse for your workload) or to opt IN on a non-Claude model id that still routes through Anthropic via OpenRouter's routing tags.
- Since:
- 0.5.0 (issue #26)
-
isFineGrainedToolStreamingEnabled
public boolean isFineGrainedToolStreamingEnabled()Whether the fine-grained tool streaming beta header will be sent (#26).
-