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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- tutorial
|
| 5 |
+
- crazyrouter
|
| 6 |
+
- openai
|
| 7 |
+
- api-gateway
|
| 8 |
+
- getting-started
|
| 9 |
+
- llm
|
| 10 |
+
language:
|
| 11 |
+
- en
|
| 12 |
+
- zh
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# π Crazyrouter Getting Started Guide
|
| 16 |
+
|
| 17 |
+
> One API key. 624+ AI models. OpenAI-compatible. Get started in 60 seconds.
|
| 18 |
+
|
| 19 |
+
## What is Crazyrouter?
|
| 20 |
+
|
| 21 |
+
[Crazyrouter](https://crazyrouter.com) is an AI API gateway. Instead of managing separate API keys for OpenAI, Anthropic, Google, DeepSeek, and dozens of other providers, you use **one key** to access them all.
|
| 22 |
+
|
| 23 |
+
It's fully **OpenAI SDK compatible** β just change the `base_url` and you're done.
|
| 24 |
+
|
| 25 |
+
---
|
| 26 |
+
|
| 27 |
+
## Step 1: Get Your API Key
|
| 28 |
+
|
| 29 |
+
1. Go to [crazyrouter.com](https://crazyrouter.com)
|
| 30 |
+
2. Sign up (free tier available)
|
| 31 |
+
3. Copy your API key (`sk-...`)
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## Step 2: Install the OpenAI SDK
|
| 36 |
+
|
| 37 |
+
```bash
|
| 38 |
+
pip install openai
|
| 39 |
+
```
|
| 40 |
+
|
| 41 |
+
That's it. No special SDK needed.
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## Step 3: Make Your First API Call
|
| 46 |
+
|
| 47 |
+
### Python
|
| 48 |
+
|
| 49 |
+
```python
|
| 50 |
+
from openai import OpenAI
|
| 51 |
+
|
| 52 |
+
client = OpenAI(
|
| 53 |
+
base_url="https://crazyrouter.com/v1",
|
| 54 |
+
api_key="sk-your-crazyrouter-key"
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
# Use any model β GPT-4o, Claude, Gemini, DeepSeek...
|
| 58 |
+
response = client.chat.completions.create(
|
| 59 |
+
model="gpt-4o-mini",
|
| 60 |
+
messages=[
|
| 61 |
+
{"role": "user", "content": "What is an API gateway?"}
|
| 62 |
+
]
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
print(response.choices[0].message.content)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### cURL
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
curl https://crazyrouter.com/v1/chat/completions \
|
| 72 |
+
-H "Content-Type: application/json" \
|
| 73 |
+
-H "Authorization: Bearer sk-your-crazyrouter-key" \
|
| 74 |
+
-d '{
|
| 75 |
+
"model": "gpt-4o-mini",
|
| 76 |
+
"messages": [{"role": "user", "content": "Hello!"}]
|
| 77 |
+
}'
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### JavaScript / Node.js
|
| 81 |
+
|
| 82 |
+
```javascript
|
| 83 |
+
import OpenAI from "openai";
|
| 84 |
+
|
| 85 |
+
const client = new OpenAI({
|
| 86 |
+
baseURL: "https://crazyrouter.com/v1",
|
| 87 |
+
apiKey: "sk-your-crazyrouter-key",
|
| 88 |
+
});
|
| 89 |
+
|
| 90 |
+
const response = await client.chat.completions.create({
|
| 91 |
+
model: "gpt-4o-mini",
|
| 92 |
+
messages: [{ role: "user", content: "Hello from Node.js!" }],
|
| 93 |
+
});
|
| 94 |
+
|
| 95 |
+
console.log(response.choices[0].message.content);
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## Step 4: Switch Models Instantly
|
| 101 |
+
|
| 102 |
+
The magic of Crazyrouter β switch between any model by changing one string:
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
# OpenAI
|
| 106 |
+
response = client.chat.completions.create(model="gpt-4o", messages=messages)
|
| 107 |
+
|
| 108 |
+
# Anthropic Claude
|
| 109 |
+
response = client.chat.completions.create(model="claude-sonnet-4-20250514", messages=messages)
|
| 110 |
+
|
| 111 |
+
# Google Gemini
|
| 112 |
+
response = client.chat.completions.create(model="gemini-2.0-flash", messages=messages)
|
| 113 |
+
|
| 114 |
+
# DeepSeek
|
| 115 |
+
response = client.chat.completions.create(model="deepseek-chat", messages=messages)
|
| 116 |
+
|
| 117 |
+
# DeepSeek R1 (reasoning)
|
| 118 |
+
response = client.chat.completions.create(model="deepseek-reasoner", messages=messages)
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
No SDK changes. No config changes. Just the model name.
|
| 122 |
+
|
| 123 |
+
---
|
| 124 |
+
|
| 125 |
+
## Step 5: Streaming Responses
|
| 126 |
+
|
| 127 |
+
```python
|
| 128 |
+
stream = client.chat.completions.create(
|
| 129 |
+
model="gpt-4o",
|
| 130 |
+
messages=[{"role": "user", "content": "Write a short poem about coding"}],
|
| 131 |
+
stream=True
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
for chunk in stream:
|
| 135 |
+
content = chunk.choices[0].delta.content
|
| 136 |
+
if content:
|
| 137 |
+
print(content, end="", flush=True)
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
---
|
| 141 |
+
|
| 142 |
+
## Step 6: List Available Models
|
| 143 |
+
|
| 144 |
+
```python
|
| 145 |
+
models = client.models.list()
|
| 146 |
+
for model in models.data:
|
| 147 |
+
print(model.id)
|
| 148 |
+
```
|
| 149 |
+
|
| 150 |
+
Or via cURL:
|
| 151 |
+
|
| 152 |
+
```bash
|
| 153 |
+
curl https://crazyrouter.com/v1/models \
|
| 154 |
+
-H "Authorization: Bearer sk-your-crazyrouter-key"
|
| 155 |
+
```
|
| 156 |
+
|
| 157 |
+
---
|
| 158 |
+
|
| 159 |
+
## Popular Models
|
| 160 |
+
|
| 161 |
+
| Model | Provider | Best For |
|
| 162 |
+
|-------|----------|----------|
|
| 163 |
+
| `gpt-4o` | OpenAI | General purpose, vision |
|
| 164 |
+
| `gpt-4o-mini` | OpenAI | Fast, cheap, good enough |
|
| 165 |
+
| `claude-sonnet-4-20250514` | Anthropic | Coding, analysis |
|
| 166 |
+
| `claude-haiku-3.5` | Anthropic | Fast, affordable |
|
| 167 |
+
| `gemini-2.0-flash` | Google | Speed, long context |
|
| 168 |
+
| `deepseek-chat` | DeepSeek | Cheap, strong coding |
|
| 169 |
+
| `deepseek-reasoner` | DeepSeek | Complex reasoning (R1) |
|
| 170 |
+
| `o3-mini` | OpenAI | Reasoning tasks |
|
| 171 |
+
|
| 172 |
+
---
|
| 173 |
+
|
| 174 |
+
## Environment Variables (Recommended)
|
| 175 |
+
|
| 176 |
+
```bash
|
| 177 |
+
export OPENAI_API_KEY="sk-your-crazyrouter-key"
|
| 178 |
+
export OPENAI_BASE_URL="https://crazyrouter.com/v1"
|
| 179 |
+
```
|
| 180 |
+
|
| 181 |
+
Then your code simplifies to:
|
| 182 |
+
|
| 183 |
+
```python
|
| 184 |
+
from openai import OpenAI
|
| 185 |
+
client = OpenAI() # Reads from env vars automatically
|
| 186 |
+
```
|
| 187 |
+
|
| 188 |
+
---
|
| 189 |
+
|
| 190 |
+
## FAQ
|
| 191 |
+
|
| 192 |
+
**Q: Is it really OpenAI-compatible?**
|
| 193 |
+
A: Yes. Any tool that works with the OpenAI API works with Crazyrouter. Just change the base URL.
|
| 194 |
+
|
| 195 |
+
**Q: Is there a free tier?**
|
| 196 |
+
A: Yes. Sign up at [crazyrouter.com](https://crazyrouter.com) to get started.
|
| 197 |
+
|
| 198 |
+
**Q: How many models are available?**
|
| 199 |
+
A: 624+ models from 20+ providers, and growing.
|
| 200 |
+
|
| 201 |
+
**Q: Can I use it with LangChain / LlamaIndex / AutoGen?**
|
| 202 |
+
A: Absolutely. See our [LangChain guide](https://huggingface.co/xujfcn/Crazyrouter-LangChain-Guide).
|
| 203 |
+
|
| 204 |
+
---
|
| 205 |
+
|
| 206 |
+
## Links
|
| 207 |
+
|
| 208 |
+
- π [Website](https://crazyrouter.com)
|
| 209 |
+
- π€ [Live Demo](https://huggingface.co/spaces/xujfcn/Crazyrouter-Demo)
|
| 210 |
+
- π° [Pricing](https://huggingface.co/spaces/xujfcn/Crazyrouter-Pricing)
|
| 211 |
+
- π [Model Pricing Dataset](https://huggingface.co/datasets/xujfcn/Crazyrouter-Model-Pricing)
|
| 212 |
+
- π¬ [Telegram Community](https://t.me/crazyrouter)
|
| 213 |
+
- π¦ [Twitter @metaviiii](https://twitter.com/metaviiii)
|