first commit
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
# 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)
|
||||
|
||||
```bash
|
||||
export ANTHROPIC_BASE_URL="http://localhost:8000/anthropic"
|
||||
export ANTHROPIC_API_KEY="<upstream-api-key>"
|
||||
claude
|
||||
```
|
||||
|
||||
### 2. Claude Code Settings JSON
|
||||
|
||||
`~/.claude/settings.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"anthropicBaseUrl": "http://localhost:8000/anthropic",
|
||||
"apiKey": "<upstream-api-key>"
|
||||
}
|
||||
```
|
||||
|
||||
## Gateway Konfigürasyonu (`.env`)
|
||||
|
||||
```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:
|
||||
|
||||
```bash
|
||||
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ı:
|
||||
|
||||
```json
|
||||
{
|
||||
"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-key` header'ı ile authentication yapar → Gateway bunu `Authorization: Bearer`'a çevirir
|
||||
- `anthropic-version` header'ı 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-stream` flag'i ile streaming'i kapatarak kullanılabilir: `claude --no-stream`
|
||||
Reference in New Issue
Block a user