3.0 KiB
3.0 KiB
ClaudeCode_Setup
Özet: Claude Code CLI'ı bu LLM Gateway üzerinden kullanmak için gerekli yapılandırma. Claude Code, Anthropic Messages API formatında konuşur; gateway /anthropic/* endpoint'i ile bunu OpenAI formatına çevirip herhangi bir OpenAI-compatible backend'e (DeepSeek, vb.) iletir.
Kütüphaneler: Claude Code CLI, Go Fiber v3
Bağlantılar: AnthropicHandler, BifrostTransform, Anthropic Flow, Config, Index
Nasıl Çalışır
Claude Code → x-api-key → Gateway /anthropic/v1/messages → AnthropicToBifrost()
↓
OpenAI Chat Completions
↓
OPENAI_BACKEND/v1/chat/completions
↓
BifrostToAnthropic()
↓
Claude Code ← Anthropic Messages API ← Gateway ← ← ← ← ← ←
Claude Code Yapılandırması
Claude Code'u gateway'e yönlendirmek için iki yol var:
1. Environment Variable (Önerilen)
export ANTHROPIC_BASE_URL="http://localhost:8000/anthropic"
export ANTHROPIC_API_KEY="<upstream-api-key>"
claude
2. Claude Code Settings JSON
~/.claude/settings.json:
{
"anthropicBaseUrl": "http://localhost:8000/anthropic",
"apiKey": "<upstream-api-key>"
}
Gateway Konfigürasyonu (.env)
PORT=8000
OPENAI_BACKEND=https://api.deepseek.com
OPENAI_KEY=sk-your-deepseek-api-key
REQUEST_TIMEOUT_SECONDS=30
| Değişken | Değer | Açıklama |
|---|---|---|
OPENAI_BACKEND |
https://api.deepseek.com |
Upstream LLM API (OpenAI-compatible) |
OPENAI_KEY |
sk-... |
Upstream API anahtarı (auto-inject) |
Test
Gateway çalışırken Claude Code'un gönderdiği formatta test:
curl -X POST "http://localhost:8000/anthropic/v1/messages" \
-H "Content-Type: application/json" \
-H "x-api-key: sk-test-key" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-sonnet-4-20250514",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Merhaba, 2+2 nedir?"}]
}'
Başarılı yanıt formatı:
{
"id": "chatcmpl-xxx",
"type": "message",
"role": "assistant",
"content": [{"type": "text", "text": "4"}],
"model": "DeepSeek/deepseek-v4",
"stop_reason": "end_turn"
}
Önemli Notlar
- Claude Code
x-api-keyheader'ı ile authentication yapar → Gateway bunuAuthorization: Bearer'a çevirir anthropic-versionheader'ı olduğu gibi upstream'e iletilir- Model adı otomatik prefix alır:
claude-sonnet-4-20250514→Anthropic/claude-sonnet-4-20250514 - Streaming (
stream: true) henüz desteklenmez — response tamamlanana kadar bekler - Claude Code
--no-streamflag'i ile streaming'i kapatarak kullanılabilir:claude --no-stream