openrouter-sdk-patterns

Featured

Build reusable OpenRouter client wrappers with retries, typing, and middleware. Use when creating SDKs or client libraries. Triggers: 'openrouter sdk', 'openrouter client wrapper', 'openrouter patterns', 'openrouter library'.

AI & Automation 2,940 stars 439 forks Updated today MIT

Install

View on GitHub

Quality Score: 99/100

Stars 20%
100
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# OpenRouter SDK Patterns ## Overview Build production-grade OpenRouter client wrappers using the OpenAI SDK. The OpenAI Python/TypeScript SDKs work natively with OpenRouter by changing `base_url` to `https://openrouter.ai/api/v1`. This skill covers typed wrappers, retry strategies, middleware, and reusable patterns. ## Python: Production Client Wrapper ```python import os, time, hashlib, json, logging from dataclasses import dataclass from typing import Optional from openai import OpenAI, APIError, RateLimitError, APITimeoutError log = logging.getLogger("openrouter") @dataclass class CompletionResult: content: str model: str prompt_tokens: int completion_tokens: int generation_id: str latency_ms: float class OpenRouterClient: def __init__( self, api_key: Optional[str] = None, app_name: str = "my-app", app_url: str = "https://my-app.com", max_retries: int = 3, timeout: float = 60.0, ): self.client = OpenAI( base_url="https://openrouter.ai/api/v1", api_key=api_key or os.environ["OPENROUTER_API_KEY"], max_retries=max_retries, # Built-in SDK retry with backoff timeout=timeout, default_headers={ "HTTP-Referer": app_url, "X-Title": app_name, }, ) self._cache: dict[str, CompletionResult] = {} def complete( self, prompt: str, model: str = "an...

Details

Author
jeremylongshore
Repository
jeremylongshore/claude-code-plugins-plus-skills
Created
1 years ago
Last Updated
today
Language
Python
License
MIT

Integrates with

Bundled in these plugins

Similar Skills

Semantically similar based on skill content — not just same category