File size: 5,243 Bytes
db86f31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22f55d9
db86f31
 
 
 
 
 
 
22f55d9
db86f31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22f55d9
db86f31
 
 
 
 
 
 
 
 
 
 
22f55d9
db86f31
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
license: mit
tags:
  - tutorial
  - crazyrouter
  - openai
  - api-gateway
  - getting-started
  - llm
language:
  - en
  - zh
---

# πŸš€ Crazyrouter Getting Started Guide

> One API key. 624+ AI models. OpenAI-compatible. Get started in 60 seconds.

## What is Crazyrouter?

[Crazyrouter](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community) 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.

It's fully **OpenAI SDK compatible** β€” just change the `base_url` and you're done.

---

## Step 1: Get Your API Key

1. Go to [crazyrouter.com](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community)
2. Sign up (free tier available)
3. Copy your API key (`sk-...`)

---

## Step 2: Install the OpenAI SDK

```bash
pip install openai
```

That's it. No special SDK needed.

---

## Step 3: Make Your First API Call

### Python

```python
from openai import OpenAI

client = OpenAI(
    base_url="https://crazyrouter.com/v1",
    api_key="sk-your-crazyrouter-key"
)

# Use any model β€” GPT-4o, Claude, Gemini, DeepSeek...
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "What is an API gateway?"}
    ]
)

print(response.choices[0].message.content)
```

### cURL

```bash
curl https://crazyrouter.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-your-crazyrouter-key" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role": "user", "content": "Hello!"}]
  }'
```

### JavaScript / Node.js

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://crazyrouter.com/v1",
  apiKey: "sk-your-crazyrouter-key",
});

const response = await client.chat.completions.create({
  model: "gpt-4o-mini",
  messages: [{ role: "user", content: "Hello from Node.js!" }],
});

console.log(response.choices[0].message.content);
```

---

## Step 4: Switch Models Instantly

The magic of Crazyrouter β€” switch between any model by changing one string:

```python
# OpenAI
response = client.chat.completions.create(model="gpt-4o", messages=messages)

# Anthropic Claude
response = client.chat.completions.create(model="claude-sonnet-4-20250514", messages=messages)

# Google Gemini
response = client.chat.completions.create(model="gemini-2.0-flash", messages=messages)

# DeepSeek
response = client.chat.completions.create(model="deepseek-chat", messages=messages)

# DeepSeek R1 (reasoning)
response = client.chat.completions.create(model="deepseek-reasoner", messages=messages)
```

No SDK changes. No config changes. Just the model name.

---

## Step 5: Streaming Responses

```python
stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a short poem about coding"}],
    stream=True
)

for chunk in stream:
    content = chunk.choices[0].delta.content
    if content:
        print(content, end="", flush=True)
```

---

## Step 6: List Available Models

```python
models = client.models.list()
for model in models.data:
    print(model.id)
```

Or via cURL:

```bash
curl https://crazyrouter.com/v1/models \
  -H "Authorization: Bearer sk-your-crazyrouter-key"
```

---

## Popular Models

| Model | Provider | Best For |
|-------|----------|----------|
| `gpt-4o` | OpenAI | General purpose, vision |
| `gpt-4o-mini` | OpenAI | Fast, cheap, good enough |
| `claude-sonnet-4-20250514` | Anthropic | Coding, analysis |
| `claude-haiku-3.5` | Anthropic | Fast, affordable |
| `gemini-2.0-flash` | Google | Speed, long context |
| `deepseek-chat` | DeepSeek | Cheap, strong coding |
| `deepseek-reasoner` | DeepSeek | Complex reasoning (R1) |
| `o3-mini` | OpenAI | Reasoning tasks |

---

## Environment Variables (Recommended)

```bash
export OPENAI_API_KEY="sk-your-crazyrouter-key"
export OPENAI_BASE_URL="https://crazyrouter.com/v1"
```

Then your code simplifies to:

```python
from openai import OpenAI
client = OpenAI()  # Reads from env vars automatically
```

---

## FAQ

**Q: Is it really OpenAI-compatible?**
A: Yes. Any tool that works with the OpenAI API works with Crazyrouter. Just change the base URL.

**Q: Is there a free tier?**
A: Yes. Sign up at [crazyrouter.com](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community) to get started.

**Q: How many models are available?**
A: 624+ models from 20+ providers, and growing.

**Q: Can I use it with LangChain / LlamaIndex / AutoGen?**
A: Absolutely. See our [LangChain guide](https://huggingface.co/xujfcn/Crazyrouter-LangChain-Guide).

---

## Links

- 🌐 [Website](https://crazyrouter.com/?utm_source=huggingface&utm_medium=tutorial&utm_campaign=dev_community)
- πŸ€– [Live Demo](https://huggingface.co/spaces/xujfcn/Crazyrouter-Demo)
- πŸ’° [Pricing](https://huggingface.co/spaces/xujfcn/Crazyrouter-Pricing)
- πŸ“Š [Model Pricing Dataset](https://huggingface.co/datasets/xujfcn/Crazyrouter-Model-Pricing)
- πŸ’¬ [Telegram Community](https://t.me/crazyrouter)
- 🐦 [Twitter @metaviiii](https://twitter.com/metaviiii)