openrouter_client
OpenRouter client package re-exporting legacy monolithic definitions for backward compatibility.
- class openrouter_client.OpenRouterClient(api_key, model='x-ai/grok-4.1-fast', temperature=1.0, max_tokens=60000, top_p=0.99, tool_registry=None, max_tool_rounds=10, base_url='http://localhost:3000/openai', gemini_api_key='', gemini_count_tokens_model='gemini-3.1-flash-lite', max_tool_output_chars=150000, http_connect_timeout=10.0, http_read_timeout=1200.0, http_write_timeout=120.0, http_pool_timeout=180.0)[source]
Bases:
OpenRouterExecutorThin async wrapper around an OpenAI-compatible chat-completions endpoint.
- Parameters:
api_key (str)
model (str)
temperature (float)
max_tokens (int)
top_p (float)
tool_registry (Any | None)
max_tool_rounds (int)
base_url (str)
gemini_api_key (str)
gemini_count_tokens_model (str)
max_tool_output_chars (int)
http_connect_timeout (float)
http_read_timeout (float)
http_write_timeout (float)
http_pool_timeout (float)
- __init__(api_key, model='x-ai/grok-4.1-fast', temperature=1.0, max_tokens=60000, top_p=0.99, tool_registry=None, max_tool_rounds=10, base_url='http://localhost:3000/openai', gemini_api_key='', gemini_count_tokens_model='gemini-3.1-flash-lite', max_tool_output_chars=150000, http_connect_timeout=10.0, http_read_timeout=1200.0, http_write_timeout=120.0, http_pool_timeout=180.0)[source]
Initialize the instance.
- Parameters:
api_key (str)
model (str)
temperature (float)
max_tokens (int)
top_p (float)
tool_registry (Any | None)
max_tool_rounds (int)
base_url (str)
gemini_api_key (str)
gemini_count_tokens_model (str)
max_tool_output_chars (int)
http_connect_timeout (float)
http_read_timeout (float)
http_write_timeout (float)
http_pool_timeout (float)
- Return type:
None
- async count_input_tokens(messages, *, gemini_model=None)[source]
Public wrapper for Gemini
countTokenson OpenAI-shaped messages.
- openrouter_client.get_tool_round_limit_box()[source]
Return the mutable
[max_rounds]for the current chat invocation.
- async openrouter_client.media_to_content_parts(data, mimetype, filename, body_text=None)[source]
Build an OpenRouter multimodal content-parts list from raw media.
Office / ODF documents are transparently converted to PDF via LibreOffice so the LLM never sees an unsupported MIME type.
- Parameters:
- Returns:
A list of content-part dicts suitable for the
contentfield of an OpenRouter user message.- Return type:
- openrouter_client.get_openrouter_api_key()[source]
Return the OpenRouter API key for the embed fallback, from env or the default.
Prefers
OPENROUTER_API_KEY, then the legacyAPI_KEYenv var, and finally_DEFAULT_OPENROUTER_KEYso the OpenRouter embed path works out-of-the-box. The result becomes theBearertoken for the embeddings endpoint.Called within this module by
openrouter_embed_batch()andopenrouter_embed_batch_sync()when no explicitapi_keyis passed.
- openrouter_client.resolve_model_alias(model)[source]
Expand a short model alias to its canonical provider model id.
The local proxy accepts friendly short names (e.g.
gemini-3-pro-preview) but routes them to a canonical backend model. Resolving the alias here ensures all downstream logic (token caps, Gemini detection, response header) sees the true model name.