# Примеры 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 @- <> ~/.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)