File size: 10,142 Bytes
e275025 |
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# Примеры Curl команд для OpenRouter API
## Установка переменных окружения
```bash
# Установите ваш API ключ
export OPENROUTER_API_KEY="sk-or-v1-..."
# Опционально: выберите модель (по умолчанию gemini-3-flash-preview)
export OPENROUTER_MODEL="google/gemini-3-flash-preview"
```
## 1. Базовый запрос
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "user",
"content": "Hello, how are you?"
}
]
}'
```
## 2. Запрос с reasoning mode (для Gemini)
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "user",
"content": "How many r'\''s are in the word strawberry?"
}
],
"reasoning": {
"enabled": true
}
}'
```
## 3. Медицинская коррекция (простая)
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "system",
"content": "Ты медицинский помощник. Исправь ошибки в медицинской транскрипции."
},
{
"role": "user",
"content": "Пациент жалуется на боль в животе, тошнота и рвота"
}
],
"temperature": 0.1,
"reasoning": {
"enabled": true
}
}'
```
## 4. Медицинская коррекция с терминами
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "system",
"content": "Ты медицинский помощник. Исправь ошибки в транскрипции, используя правильную медицинскую терминологию.\n\nМедицинские термины: аппендицит, гастрит, энцефалопатия, кардиомиопатия, артериальная гипертензия, сахарный диабет"
},
{
"role": "user",
"content": "У пациента подозрение на апендицит и гастрит. Также отмечается повышенное давление."
}
],
"temperature": 0.1,
"max_tokens": 2000,
"reasoning": {
"enabled": true
}
}'
```
## 5. Запрос с дополнительными заголовками
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-H "HTTP-Referer: http://localhost" \
-H "X-Title: Trans_for_doctors" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "user",
"content": "Привет!"
}
]
}'
```
## 6. Использование другой модели (GPT-4o)
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "openai/gpt-4o",
"messages": [
{
"role": "system",
"content": "Ты медицинский эксперт. Исправь транскрипцию."
},
{
"role": "user",
"content": "Пациент жалуется на боль в животе"
}
],
"temperature": 0.1
}'
```
## 7. Использование Claude
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "anthropic/claude-3.5-sonnet",
"messages": [
{
"role": "user",
"content": "Исправь медицинскую транскрипцию: Пациент с диагнозом апендицит"
}
],
"temperature": 0.1
}'
```
## 8. Форматированный вывод (с jq)
```bash
curl -s https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "user",
"content": "Hello!"
}
]
}' | jq '.choices[0].message.content'
```
## 9. Сохранение ответа в файл
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "user",
"content": "Исправь: Пациент жалуется на боль"
}
]
}' > response.json
```
## 10. Batch обработка (скрипт)
```bash
#!/bin/bash
TEXTS=(
"Пациент жалуется на боль в животе"
"Диагноз апендицит"
"Высокая температура и кашель"
)
for text in "${TEXTS[@]}"; do
echo "Обработка: $text"
curl -s https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d "{
\"model\": \"google/gemini-3-flash-preview\",
\"messages\": [
{
\"role\": \"system\",
\"content\": \"Исправь медицинский текст\"
},
{
\"role\": \"user\",
\"content\": \"$text\"
}
],
\"temperature\": 0.1
}" | jq -r '.choices[0].message.content'
echo "---"
done
```
## 11. Проверка статуса API
```bash
curl -s https://openrouter.ai/api/v1/models \
-H "Authorization: Bearer $OPENROUTER_API_KEY" | jq
```
## 12. Получение информации о модели
```bash
curl -s https://openrouter.ai/api/v1/models \
-H "Authorization: Bearer $OPENROUTER_API_KEY" | \
jq '.data[] | select(.id == "google/gemini-3-flash-preview")'
```
## 13. Multiline текст (heredoc)
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d @- <<EOF
{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "system",
"content": "Ты медицинский помощник"
},
{
"role": "user",
"content": "Пациент жалуется на:\n- боль в животе\n- тошноту\n- рвоту"
}
],
"temperature": 0.1
}
EOF
```
## 14. С таймаутом
```bash
curl --max-time 30 https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "user",
"content": "Quick test"
}
]
}'
```
## 15. Подробный вывод (verbose)
```bash
curl -v https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [
{
"role": "user",
"content": "Test"
}
]
}'
```
## Использование готового скрипта
Проект включает готовый bash скрипт для тестирования:
```bash
# Базовое использование
./test_openrouter_curl.sh
# С кастомным текстом
./test_openrouter_curl.sh "Ваш текст для обработки"
# С переменной окружения для модели
OPENROUTER_MODEL="openai/gpt-4o" ./test_openrouter_curl.sh "Текст"
```
## Обработка ошибок
```bash
response=$(curl -s -w "\n%{http_code}" https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '{
"model": "google/gemini-3-flash-preview",
"messages": [{"role": "user", "content": "Test"}]
}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)
if [ "$http_code" -eq 200 ]; then
echo "Success: $body"
else
echo "Error ($http_code): $body"
fi
```
## Полезные советы
1. **Сохраните API ключ в переменной окружения**:
```bash
echo "export OPENROUTER_API_KEY='your-key'" >> ~/.bashrc
source ~/.bashrc
```
2. **Установите jq для форматирования JSON**:
```bash
# Ubuntu/Debian
sudo apt-get install jq
# macOS
brew install jq
```
3. **Используйте файлы для больших промптов**:
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d @request.json
```
4. **Логируйте запросы для отладки**:
```bash
curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer $OPENROUTER_API_KEY" \
-d '...' | tee response.log
```
## Дополнительные ресурсы
- [OpenRouter API Docs](https://openrouter.ai/docs)
- [Список моделей](https://openrouter.ai/models)
- [Примеры в Python](test_openrouter.py)
- [Полная документация](corrector/OPENROUTER.md)
|