c56ae7194c
- Updated AnthropicHandler to check for streaming configuration before handling SSE transform. - Modified handleStreaming to use the original request body instead of forcing stream to true. - Adjusted the transformation logic in AnthropicToBifrost to respect the original stream setting. - Added logging for SSE streaming configuration in the main application.
1.9 KiB
1.9 KiB
AnthropicHandler
Özet: /anthropic/* route'unu karşılar (handlers/anthropic.go:75). Anthropic Messages API formatını OpenAI Chat Completions formatına çevirir (Bifrost), upstream'e iletir ve yanıtı geri Anthropic formatına dönüştürür.
Kütüphaneler: Fiber v3, GORM, Go encoding/json
Bağlantılar: Main, BifrostTransform, ProxyEngine, RequestLog, Config, Anthropic Flow
Davranış
GET /v1/models→ AnthropicHandler#modelsListHEAD→ 404 (DeepSeek uyumluluğu)- Empty body → varsayılan "optoant gateway ready" yanıtı
x-api-key→Authorization: Bearerdönüşümü (Claude Code uyumluluğu)- Gerekirse
OPENAI_KEY'den auto-inject - BifrostTransform#AnthropicToBifrost ile dönüşüm
- Client
stream: truegönderdiyse veSTREAMING=trueise → #handleStreaming - ProxyEngine ile
OPENAI_BACKEND/v1/chat/completions'a forward - Başarılıysa (200): BifrostTransform#BifrostToAnthropic → Anthropic format
- Hata durumunda: raw passthrough
- DB log (fire-and-forget)
Endpoint
POST /anthropic/v1/messages
x-api-key: <api-key>
# veya
Authorization: Bearer <api-key>
Modeller (modelsList())
| ID | Display Name |
|---|---|
deepseek-v4-flash |
DeepSeek V4 Flash |
deepseek-v4-pro |
DeepSeek V4 Pro |
Ek Fonksiyonlar
| Fonksiyon | Açıklama |
|---|---|
infoPage() |
GET /anthropic (boş path) için HTML bilgi sayfası |
modelsList() |
GET /anthropic/v1/models için model listesi |
Edge Case'ler
- Geçersiz Anthropic formatı → uyarı log'u + raw passthrough
- Upstream hatası →
502 Bad Gateway - Yanıt dönüşüm hatası → raw yanıtı forward et
STREAMING=false→ clientstream: trueisteği görmezden gelinir, non-streaming yanıt döner