OpenRouterLLM¶
cogitator.model.openrouter
¶
Provides an LLM provider implementation for interacting with OpenRouter API.
OpenRouterLLM
¶
Bases: OpenAILLM
LLM provider implementation for OpenRouter API.
OpenRouter provides access to 300+ models through an OpenAI-compatible API. This class extends OpenAILLM and configures it to use the OpenRouter endpoint.
Model names follow the format: provider/model (e.g., "openai/gpt-4o-mini", "anthropic/claude-3.5-sonnet", "meta-llama/llama-3.1-70b-instruct").
Reference
OpenRouter API Documentation: https://openrouter.ai/docs
Source code in cogitator/model/openrouter.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | |
__init__(api_key, model='openai/gpt-4o-mini', temperature=0.7, max_tokens=512, stop=None, seed=33, retry_attempts=3, retry_backoff=1.0, site_url=None, site_name=None)
¶
Initializes the OpenRouterLLM provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
Your OpenRouter API key. |
required |
model
|
str
|
The model identifier in provider/model format (e.g., "openai/gpt-4o-mini", "anthropic/claude-3.5-sonnet"). |
'openai/gpt-4o-mini'
|
temperature
|
float
|
The sampling temperature for generation. |
0.7
|
max_tokens
|
int
|
The maximum number of tokens to generate. |
512
|
stop
|
Optional[List[str]]
|
A list of sequences where the API will stop generation. |
None
|
seed
|
Optional[int]
|
The random seed for reproducibility (if supported by the model). |
33
|
retry_attempts
|
int
|
Number of retries upon API call failure. |
3
|
retry_backoff
|
float
|
Initial backoff factor for retries (exponential). |
1.0
|
site_url
|
Optional[str]
|
Optional URL of your site for OpenRouter tracking/rankings. |
None
|
site_name
|
Optional[str]
|
Optional name of your site for OpenRouter tracking. |
None
|