Files
opantoantro/docs/wiki/OpenAI_Flow.md
T
Beyhan Ogur a408821410 first commit
2026-05-11 15:08:50 +03:00

39 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OpenAI Flow
**Özet:** OpenAI-compatible isteklerin gateway üzerinden direkt passthrough akışı.
**Kütüphaneler:** Fiber v3, Go `net/http`
**Bağlantılar:** [[OpenAIHandler]], [[ProxyEngine]], [[RequestLog]], [[Index]]
## Akış Diyagramı
```mermaid
sequenceDiagram
participant Client
participant Gateway
participant Proxy
participant Upstream
participant DB
Client->>Gateway: POST /v1/chat/completions
Note over Gateway: OpenAIHandler
Gateway->>Gateway: fiberToHTTPHeaders()
Gateway->>Gateway: API key auto-inject (gerekirse)
Gateway->>Gateway: copyResponseHeaders()
Gateway->>Proxy: Forward(method, targetURL, headers, body, timeout)
Proxy->>Upstream: POST <OPENAI_BACKEND>/v1/chat/completions
Upstream-->>Proxy: 200 OK + response body
Proxy-->>Gateway: ForwardResult{StatusCode, Body, Headers}
Gateway->>Gateway: copyResponseHeaders() (skip hop-by-hop)
Gateway->>DB: go db.Create(logEntry) — fire-and-forget
Gateway-->>Client: 200 OK + original response body
```
## Önemli Noktalar
- İstek body'si **olduğu gibi** iletilir (dönüşüm yok)
- Response header'ları kopyalanırken `Transfer-Encoding`, `Content-Length`, `Connection` atlanır
- Upstream hatasında client `502 Bad Gateway` alır
- DB loglama bir goroutine içinde çalışır, asla ana isteği bloke etmez