1 line
20 KiB
JSON
1 line
20 KiB
JSON
{"repo": "0xdewy/skills", "files": {"skills/llm-providers/references/openrouter.md": {"6b74f4230a4a3889cd1ffcb9d21239a15e5ad1c5": {"t": 1785746516.0131464, "n": 5204, "h": "5bac8320a227886f", "c": "# OpenRouter\n\nOpenRouter is a single OpenAI-compatible gateway to hundreds of models from\nOpenAI, Anthropic, Google, Meta, Mistral, xAI, DeepSeek, Qwen, and many\nothers. One key, one SDK, one bill. (verified 2026-07)\n\n## Get an API key\n\n`https://openrouter.ai/keys` → set `OPENROUTER_API_KEY`. Keys look like\n`sk-or-v1-...`. Add credits on the dashboard; pay-as-you-go, no per-provider\nsignup.\n\n```bash\nexport OPENROUTER_API_KEY=\"sk-or-v1-...\"\n```\n\n## Base URL & auth\n\n- Base URL: `https://openrouter.ai/api/v1`\n- Auth: `Authorization: Bearer $OPENROUTER_API_KEY`\n- Endpoint: `POST /chat/completions` (OpenAI-shaped) — and\n `POST /completions`, `POST /embeddings`, plus `/images/generations`.\n- Optional attribution headers (no auth function, but useful for the\n OpenRouter leaderboard):\n - `HTTP-Referer: https://your-app.example`\n - `X-Title: Your App Name`\n\n## SDKs\n\n| Lang | Package | Notes |\n|---|---|---|\n| Any | `pip install openai` / `npm install openai` | works at the compat URL |\n| Python | `pip install openrouter` (community) | thin |\n| TypeScript / Node | community only | use `openai` SDK |\n\n## Samples\n\n### curl\n\n```bash\ncurl https://openrouter.ai/api/v1/chat/completions \\\n -H \"Authorization: Bearer $OPENROUTER_API_KEY\" \\\n -H \"HTTP-Referer: https://example.com\" \\\n -H \"X-Title: Demo App\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"model\": \"anthropic/claude-sonnet-4.5\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}]\n }'\n```\n\n### Python\n\n```python\nimport os\nfrom openai import OpenAI\n\nclient = OpenAI(\n base_url=\"https://openrouter.ai/api/v1\",\n api_key=os.environ[\"OPENROUTER_API_KEY\"],\n)\nresp = client.chat.completions.create(\n model=\"anthropic/claude-sonnet-4.5\",\n messages=[{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}],\n)\nprint(resp.choices[0].message.content)\n```\n\n### Routing — fallbacks, caching, and provider choice\n\nOpenRouter's differentiator is the `provider` routing block:\n\n```python\nresp = client.chat.completions.create(\n model=\"anthropic/claude-sonnet-4.5\",\n messages=[...],\n extra_body={\n \"provider\": {\n \"order\": [\"Anthropic\", \"AWS Bedrock\"], # try in this order\n \"allow_fallbacks\": True,\n \"require_parameters\": True,\n },\n \"fallbacks\": [\"openai/gpt-4.1\", \"google/gemini-2.5-pro\"],\n \"transforms\": [\"middle-out\"], # auto-compress long context\n \"max_tokens\": 1024,\n },\n)\n```\n\n- `order`/`allow_fallbacks` — try one provider backend, then another.\n- `fallbacks` — try a different *model* if the primary is down.\n- `transforms` — `middle-out` compresses long context to fit.\n- `usage`/`cost` are returned on every response.\n\n### TypeScript\n\n```typescript\nimport OpenAI from \"openai\";\nconst client = new OpenAI({\n baseURL: \"https://openrouter.ai/api/v1\",\n apiKey: process.env.OPENROUTER_API_KEY,\n defaultHeaders: {\n \"HTTP-Referer\": \"https://example.com\",\n \"X-Title\": \"Demo App\",\n },\n});\nconst resp = await client.chat.completions.create({\n model: \"openai/gpt-4.1\",\n messages: [{ role: \"user\", content: \"Say hello in one short sentence.\" }],\n});\nconsole.log(resp.choices[0].message.content);\n```\n\n## Model strings\n\nThe model id is always `provider/model-name`. Examples (verify at\n`https://openrouter.ai/models` for the live list):\n\n- `openai/gpt-4.1`, `openai/gpt-4o`, `openai/gpt-5` (when available)\n- `anthropic/claude-sonnet-4.5`, `anthropic/claude-opus-4.1`,\n `anthropic/claude-haiku-4.5`\n- `google/gemini-2.5-pro`, `google/gemini-2.5-flash`,\n `google/gemini-3-pro` (when available)\n- `x-ai/grok-4`, `x-ai/grok-4-fast`\n- `deepseek/deepseek-chat`, `deepseek/deepseek-r1`\n- `qwen/qwen3-235b-a22b`, `qwen/qwen-2.5-72b-instruct`\n- `mistralai/mistral-large-2411`, `mistralai/codestral-2501`\n- `meta-llama/llama-3.3-70b-instruct`\n- `moonshotai/kimi-k2`\n- `zhipuai/glm-4.6`\n\nSome ids carry a `:free` suffix (`meta-llama/llama-3.3-70b-instruct:free`)\nfor the free-tier endpoint with stricter rate limits.\n\n## Gotchas\n\n- **Routing adds latency**: when `allow_fallbacks=True`, the first failed\n request still incurs connection time before retrying on another provider.\n For latency-sensitive paths pin a single `provider.order`.\n- **Pricing is per-provider, not a markup floor**: OpenRouter shows input +\n output $/M-token for each model on the model page. Cheapest path can be\n to call the provider directly; OpenRouter's value is one key + fallback.\n- **`reasoning` field**: for reasoning models OpenRouter passes the upstream\n `reasoning` / `reasoning_content` through on the delta; read both\n defensively.\n- **`provider` block goes in `extra_body`** on the openai SDK because it's\n OpenRouter-specific schema.\n- **Free tier (`:free`)**: rate-limited and may route to a community cache;\n don't use for production. Fine for smoke tests.\n- **Credits**: OpenRouter prepay is shared across providers. When your\n balance runs out mid-stream, the stream ends with a 402.\n- **Anthropic/Gemini via OpenRouter** is OpenAI-shaped (the OpenRouter\n normalizer); this is a convenient way to skip Anthropic's `x-api-key`\n + Messages-specific shape if you only need chat.\n"}, "bb6d8aa24762fa7f08b62a3c99b7026bf69d4325": {"t": 1785765180.0743465, "n": 5204, "h": "5bac8320a227886f", "c": "# OpenRouter\n\nOpenRouter is a single OpenAI-compatible gateway to hundreds of models from\nOpenAI, Anthropic, Google, Meta, Mistral, xAI, DeepSeek, Qwen, and many\nothers. One key, one SDK, one bill. (verified 2026-07)\n\n## Get an API key\n\n`https://openrouter.ai/keys` → set `OPENROUTER_API_KEY`. Keys look like\n`sk-or-v1-...`. Add credits on the dashboard; pay-as-you-go, no per-provider\nsignup.\n\n```bash\nexport OPENROUTER_API_KEY=\"sk-or-v1-...\"\n```\n\n## Base URL & auth\n\n- Base URL: `https://openrouter.ai/api/v1`\n- Auth: `Authorization: Bearer $OPENROUTER_API_KEY`\n- Endpoint: `POST /chat/completions` (OpenAI-shaped) — and\n `POST /completions`, `POST /embeddings`, plus `/images/generations`.\n- Optional attribution headers (no auth function, but useful for the\n OpenRouter leaderboard):\n - `HTTP-Referer: https://your-app.example`\n - `X-Title: Your App Name`\n\n## SDKs\n\n| Lang | Package | Notes |\n|---|---|---|\n| Any | `pip install openai` / `npm install openai` | works at the compat URL |\n| Python | `pip install openrouter` (community) | thin |\n| TypeScript / Node | community only | use `openai` SDK |\n\n## Samples\n\n### curl\n\n```bash\ncurl https://openrouter.ai/api/v1/chat/completions \\\n -H \"Authorization: Bearer $OPENROUTER_API_KEY\" \\\n -H \"HTTP-Referer: https://example.com\" \\\n -H \"X-Title: Demo App\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"model\": \"anthropic/claude-sonnet-4.5\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}]\n }'\n```\n\n### Python\n\n```python\nimport os\nfrom openai import OpenAI\n\nclient = OpenAI(\n base_url=\"https://openrouter.ai/api/v1\",\n api_key=os.environ[\"OPENROUTER_API_KEY\"],\n)\nresp = client.chat.completions.create(\n model=\"anthropic/claude-sonnet-4.5\",\n messages=[{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}],\n)\nprint(resp.choices[0].message.content)\n```\n\n### Routing — fallbacks, caching, and provider choice\n\nOpenRouter's differentiator is the `provider` routing block:\n\n```python\nresp = client.chat.completions.create(\n model=\"anthropic/claude-sonnet-4.5\",\n messages=[...],\n extra_body={\n \"provider\": {\n \"order\": [\"Anthropic\", \"AWS Bedrock\"], # try in this order\n \"allow_fallbacks\": True,\n \"require_parameters\": True,\n },\n \"fallbacks\": [\"openai/gpt-4.1\", \"google/gemini-2.5-pro\"],\n \"transforms\": [\"middle-out\"], # auto-compress long context\n \"max_tokens\": 1024,\n },\n)\n```\n\n- `order`/`allow_fallbacks` — try one provider backend, then another.\n- `fallbacks` — try a different *model* if the primary is down.\n- `transforms` — `middle-out` compresses long context to fit.\n- `usage`/`cost` are returned on every response.\n\n### TypeScript\n\n```typescript\nimport OpenAI from \"openai\";\nconst client = new OpenAI({\n baseURL: \"https://openrouter.ai/api/v1\",\n apiKey: process.env.OPENROUTER_API_KEY,\n defaultHeaders: {\n \"HTTP-Referer\": \"https://example.com\",\n \"X-Title\": \"Demo App\",\n },\n});\nconst resp = await client.chat.completions.create({\n model: \"openai/gpt-4.1\",\n messages: [{ role: \"user\", content: \"Say hello in one short sentence.\" }],\n});\nconsole.log(resp.choices[0].message.content);\n```\n\n## Model strings\n\nThe model id is always `provider/model-name`. Examples (verify at\n`https://openrouter.ai/models` for the live list):\n\n- `openai/gpt-4.1`, `openai/gpt-4o`, `openai/gpt-5` (when available)\n- `anthropic/claude-sonnet-4.5`, `anthropic/claude-opus-4.1`,\n `anthropic/claude-haiku-4.5`\n- `google/gemini-2.5-pro`, `google/gemini-2.5-flash`,\n `google/gemini-3-pro` (when available)\n- `x-ai/grok-4`, `x-ai/grok-4-fast`\n- `deepseek/deepseek-chat`, `deepseek/deepseek-r1`\n- `qwen/qwen3-235b-a22b`, `qwen/qwen-2.5-72b-instruct`\n- `mistralai/mistral-large-2411`, `mistralai/codestral-2501`\n- `meta-llama/llama-3.3-70b-instruct`\n- `moonshotai/kimi-k2`\n- `zhipuai/glm-4.6`\n\nSome ids carry a `:free` suffix (`meta-llama/llama-3.3-70b-instruct:free`)\nfor the free-tier endpoint with stricter rate limits.\n\n## Gotchas\n\n- **Routing adds latency**: when `allow_fallbacks=True`, the first failed\n request still incurs connection time before retrying on another provider.\n For latency-sensitive paths pin a single `provider.order`.\n- **Pricing is per-provider, not a markup floor**: OpenRouter shows input +\n output $/M-token for each model on the model page. Cheapest path can be\n to call the provider directly; OpenRouter's value is one key + fallback.\n- **`reasoning` field**: for reasoning models OpenRouter passes the upstream\n `reasoning` / `reasoning_content` through on the delta; read both\n defensively.\n- **`provider` block goes in `extra_body`** on the openai SDK because it's\n OpenRouter-specific schema.\n- **Free tier (`:free`)**: rate-limited and may route to a community cache;\n don't use for production. Fine for smoke tests.\n- **Credits**: OpenRouter prepay is shared across providers. When your\n balance runs out mid-stream, the stream ends with a 402.\n- **Anthropic/Gemini via OpenRouter** is OpenAI-shaped (the OpenRouter\n normalizer); this is a convenient way to skip Anthropic's `x-api-key`\n + Messages-specific shape if you only need chat.\n"}}, "skills/llm-providers/references/deepseek.md": {"6b74f4230a4a3889cd1ffcb9d21239a15e5ad1c5": {"t": 1785746551.8733737, "n": 4350, "h": "52258e751f107474", "c": "# DeepSeek\n\nChinese lab with an OpenAI-compatible hosted API — drop-in for the `openai` SDK.\n(verified 2026-07; both `deepseek-chat` and `deepseek-reasoner` snippets in\nthis card were run live and returned the expected content and\n`reasoning_content` separation.)\n\n## Get an API key\n\n`https://platform.deepseek.com/api_keys` → set `DEEPSEEK_API_KEY`. Keys look\nlike `sk-...` (no `proj` suffix).\n\n```bash\nexport DEEPSEEK_API_KEY=\"sk-...\"\n```\n\n## Base URL & auth\n\n- Base URL: `https://api.deepseek.com/v1` (the host root\n `https://api.deepseek.com` also works — the SDK appends `/chat/completions`).\n- Auth: `Authorization: Bearer $DEEPSEEK_API_KEY`\n- Endpoint: `POST /chat/completions` (OpenAI-shaped)\n\n## SDKs\n\nUse the `openai` SDK pointed at the DeepSeek base URL. There is no first-party\nSDK you need.\n\n| Lang | Package |\n|---|---|\n| Python | `pip install openai` |\n| TypeScript / Node | `npm install openai` |\n\n## Samples\n\n### curl\n\n```bash\ncurl https://api.deepseek.com/v1/chat/completions \\\n -H \"Authorization: Bearer $DEEPSEEK_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"model\": \"deepseek-chat\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}]\n }'\n```\n\n### Python\n\n```python\nimport os\nfrom openai import OpenAI\n\nclient = OpenAI(\n base_url=\"https://api.deepseek.com/v1\",\n api_key=os.environ[\"DEEPSEEK_API_KEY\"],\n)\nresp = client.chat.completions.create(\n model=\"deepseek-chat\",\n messages=[{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}],\n)\nprint(resp.choices[0].message.content)\n```\n\n### Streaming + reasoning (Python)\n\n```python\nclient = OpenAI(base_url=\"https://api.deepseek.com/v1\", api_key=os.environ[\"DEEPSEEK_API_KEY\"])\nstream = client.chat.completions.create(\n model=\"deepseek-reasoner\",\n messages=[{\"role\": \"user\", \"content\": \"Prove that the sum of two evens is even.\"}],\n stream=True,\n)\nfor chunk in stream:\n delta = chunk.choices[0].delta\n # R1 emits chain-of-thought in a separate field\n if getattr(delta, \"reasoning_content\", None):\n print(f\"[think] {delta.reasoning_content}\", end=\"\", flush=True)\n elif delta.content:\n print(delta.content, end=\"\", flush=True)\n```\n\n### TypeScript\n\n```typescript\nimport OpenAI from \"openai\";\nconst client = new OpenAI({\n baseURL: \"https://api.deepseek.com/v1\",\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\nconst resp = await client.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [{ role: \"user\", content: \"Say hello in one short sentence.\" }],\n});\nconsole.log(resp.choices[0].message.content);\n```\n\n## Current models\n\n- `deepseek-chat` — aliases to DeepSeek's current general flagship (DeepSeek-V3\n at launch; verified 2026-07 it returns `deepseek-v4-flash` as the underlying\n id, so the alias rolls forward as DeepSeek ships new generations — pin a\n specific snapshot id if you need reproducible behavior)\n- `deepseek-reasoner` — DeepSeek-R1 reasoning model. Outputs chain of thought\n in `message.reasoning_content`; the final answer is in `message.content`.\n `temperature`, `top_p`, and most other sampling params are ignored.\n\nModel list at `https://api-docs.deepseek.com/quick_start/pricing` is\nauthoritative. The V3/R1 weights are also on HuggingFace\n(`deepseek-ai/DeepSeek-V3`, `deepseek-ai/DeepSeek-R1`) for self-hosting via\nTogether/Groq/your own vLLM.\n\n## Gotchas\n\n- **OpenAI-compat, not OpenAI**: works with the openai SDK as long as you set\n `base_url`. Don't expect newer OpenAI features (`reasoning_effort`, Responses\n API) to exist.\n- **R1 reasoning field**: `delta.reasoning_content` is DeepSeek-specific —\n OpenAI's SDK passes it through but won't document it. Use `getattr(...,\n None)` defensively in Python.\n- **JSON mode**: pass `response_format={\"type\": \"json_object\"}` like OpenAI,\n and prompt the model to produce JSON.\n- **FIM / completions**: `/beta/completions` supports Fill-in-the-Middle for\n code editing (`prefix`/`suffix` body fields).\n- **Region**: the international endpoint at `api.deepseek.com` is the\n recommended one for non-China users; mainland-only accounts may use\n `api.deepseek.com` after registering with a +86 phone — keys and pricing are\n the same.\n- **Pricing is aggressive** vs. frontier US models; DeepSeek is a common pick\n when cost per token matters and a hosted OpenAI-compat endpoint is wanted.\n"}, "bb6d8aa24762fa7f08b62a3c99b7026bf69d4325": {"t": 1785765184.6359928, "n": 4350, "h": "52258e751f107474", "c": "# DeepSeek\n\nChinese lab with an OpenAI-compatible hosted API — drop-in for the `openai` SDK.\n(verified 2026-07; both `deepseek-chat` and `deepseek-reasoner` snippets in\nthis card were run live and returned the expected content and\n`reasoning_content` separation.)\n\n## Get an API key\n\n`https://platform.deepseek.com/api_keys` → set `DEEPSEEK_API_KEY`. Keys look\nlike `sk-...` (no `proj` suffix).\n\n```bash\nexport DEEPSEEK_API_KEY=\"sk-...\"\n```\n\n## Base URL & auth\n\n- Base URL: `https://api.deepseek.com/v1` (the host root\n `https://api.deepseek.com` also works — the SDK appends `/chat/completions`).\n- Auth: `Authorization: Bearer $DEEPSEEK_API_KEY`\n- Endpoint: `POST /chat/completions` (OpenAI-shaped)\n\n## SDKs\n\nUse the `openai` SDK pointed at the DeepSeek base URL. There is no first-party\nSDK you need.\n\n| Lang | Package |\n|---|---|\n| Python | `pip install openai` |\n| TypeScript / Node | `npm install openai` |\n\n## Samples\n\n### curl\n\n```bash\ncurl https://api.deepseek.com/v1/chat/completions \\\n -H \"Authorization: Bearer $DEEPSEEK_API_KEY\" \\\n -H \"Content-Type: application/json\" \\\n -d '{\n \"model\": \"deepseek-chat\",\n \"messages\": [{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}]\n }'\n```\n\n### Python\n\n```python\nimport os\nfrom openai import OpenAI\n\nclient = OpenAI(\n base_url=\"https://api.deepseek.com/v1\",\n api_key=os.environ[\"DEEPSEEK_API_KEY\"],\n)\nresp = client.chat.completions.create(\n model=\"deepseek-chat\",\n messages=[{\"role\": \"user\", \"content\": \"Say hello in one short sentence.\"}],\n)\nprint(resp.choices[0].message.content)\n```\n\n### Streaming + reasoning (Python)\n\n```python\nclient = OpenAI(base_url=\"https://api.deepseek.com/v1\", api_key=os.environ[\"DEEPSEEK_API_KEY\"])\nstream = client.chat.completions.create(\n model=\"deepseek-reasoner\",\n messages=[{\"role\": \"user\", \"content\": \"Prove that the sum of two evens is even.\"}],\n stream=True,\n)\nfor chunk in stream:\n delta = chunk.choices[0].delta\n # R1 emits chain-of-thought in a separate field\n if getattr(delta, \"reasoning_content\", None):\n print(f\"[think] {delta.reasoning_content}\", end=\"\", flush=True)\n elif delta.content:\n print(delta.content, end=\"\", flush=True)\n```\n\n### TypeScript\n\n```typescript\nimport OpenAI from \"openai\";\nconst client = new OpenAI({\n baseURL: \"https://api.deepseek.com/v1\",\n apiKey: process.env.DEEPSEEK_API_KEY,\n});\nconst resp = await client.chat.completions.create({\n model: \"deepseek-chat\",\n messages: [{ role: \"user\", content: \"Say hello in one short sentence.\" }],\n});\nconsole.log(resp.choices[0].message.content);\n```\n\n## Current models\n\n- `deepseek-chat` — aliases to DeepSeek's current general flagship (DeepSeek-V3\n at launch; verified 2026-07 it returns `deepseek-v4-flash` as the underlying\n id, so the alias rolls forward as DeepSeek ships new generations — pin a\n specific snapshot id if you need reproducible behavior)\n- `deepseek-reasoner` — DeepSeek-R1 reasoning model. Outputs chain of thought\n in `message.reasoning_content`; the final answer is in `message.content`.\n `temperature`, `top_p`, and most other sampling params are ignored.\n\nModel list at `https://api-docs.deepseek.com/quick_start/pricing` is\nauthoritative. The V3/R1 weights are also on HuggingFace\n(`deepseek-ai/DeepSeek-V3`, `deepseek-ai/DeepSeek-R1`) for self-hosting via\nTogether/Groq/your own vLLM.\n\n## Gotchas\n\n- **OpenAI-compat, not OpenAI**: works with the openai SDK as long as you set\n `base_url`. Don't expect newer OpenAI features (`reasoning_effort`, Responses\n API) to exist.\n- **R1 reasoning field**: `delta.reasoning_content` is DeepSeek-specific —\n OpenAI's SDK passes it through but won't document it. Use `getattr(...,\n None)` defensively in Python.\n- **JSON mode**: pass `response_format={\"type\": \"json_object\"}` like OpenAI,\n and prompt the model to produce JSON.\n- **FIM / completions**: `/beta/completions` supports Fill-in-the-Middle for\n code editing (`prefix`/`suffix` body fields).\n- **Region**: the international endpoint at `api.deepseek.com` is the\n recommended one for non-China users; mainland-only accounts may use\n `api.deepseek.com` after registering with a +86 phone — keys and pricing are\n the same.\n- **Pricing is aggressive** vs. frontier US models; DeepSeek is a common pick\n when cost per token matters and a hosted OpenAI-compat endpoint is wanted.\n"}}}} |