Asynchronous handler for OpenRouter API requests using httpx, with mapping for user-friendly model names.
| 12 | logger = logging.getLogger("openrouter_handler") |
| 13 | |
| 14 | class OpenRouterAPIHandler(BaseAPIHandler): |
| 15 | """ |
| 16 | Asynchronous handler for OpenRouter API requests using httpx, |
| 17 | with mapping for user-friendly model names. |
| 18 | """ |
| 19 | OPENROUTER_API_URL = "https://openrouter.ai/api/v1/chat/completions" |
| 20 | |
| 21 | def __init__(self): |
| 22 | super().__init__("openrouter") |
| 23 | |
| 24 | # {"name": "google/gemini-2.0-flash-exp:free", "parameters": "unknown"}, |
| 25 | # {"name": "google/gemma-3-27b-it:free", "parameters": "27B"}, |
| 26 | # {"name": "deepseek/deepseek-r1-zero:free", "parameters": "671B"}, |
| 27 | # {"name": "deepseek/deepseek-v3-base:free", "parameters": "671B"}, # Example model ID |
| 28 | |
| 29 | # --- Model Mapping --- |
| 30 | # Dictionary mapping display names to actual model IDs and parameter sizes |
| 31 | self.model_map = { |
| 32 | # --- Add your desired mappings here --- |
| 33 | # "gemma-3-27b-or": { |
| 34 | # "model_id": "google/gemma-3-27b-it:free", |
| 35 | # "parameters": "27B", |
| 36 | # "multimodal": True |
| 37 | # }, |
| 38 | "Qwen3-VL-8B": { |
| 39 | "model_id": "qwen/qwen3-vl-8b-instruct", |
| 40 | "parameters": "8B", |
| 41 | "multimodal": True, |
| 42 | "pro": True, |
| 43 | }, |
| 44 | |
| 45 | "OpenAI GPT-5": { |
| 46 | "model_id": "openai/gpt-5-mini", |
| 47 | "parameters": "N/A", |
| 48 | "multimodal": True, |
| 49 | "pro": True, |
| 50 | }, |
| 51 | |
| 52 | "OpenAI GPT-4o-mini": { |
| 53 | "model_id": "openai/gpt-4o-mini", |
| 54 | "parameters": "N/A", |
| 55 | "multimodal": True, |
| 56 | "pro": True, |
| 57 | }, |
| 58 | "xAI Grok 4 Fast": { |
| 59 | "model_id": "x-ai/grok-4-fast", |
| 60 | "parameters": "N/A", |
| 61 | "multimodal": True, |
| 62 | "pro": True, |
| 63 | }, |
| 64 | "Nemotron Nano V2": { |
| 65 | "model_id": "nvidia/nemotron-nano-9b-v2:free", |
| 66 | "parameters": "9B", |
| 67 | "multimodal": False |
| 68 | }, |
| 69 | "Nemotron Nano V2 VL": { |
| 70 | "model_id": "nvidia/nemotron-nano-12b-v2-vl:free", |
| 71 | "parameters": "12B", |