mirror of
https://github.com/lukaszraczylo/traefik-llmgateway.git
synced 2026-12-06 11:03:52 +00:00
feat(messages): stream /v1/messages responses
A request with "stream": true on POST /v1/messages now gets the Anthropic Messages event stream instead of a 400. Claude Code streams every call, so the route must stream before it can front an OpenAI-compatible cluster. For openai and gemini providers, the gateway asks the upstream for a stream with include_usage and translates each chunk as it arrives. It emits message_start, one content block group per text or tool_use block, then message_delta and message_stop. Tool call arguments arrive as input_json_delta. The stop reason uses the non-streaming mapping. For anthropic providers, the gateway relays each upstream event and rewrites only message.model in message_start. An upstream error event reaches the client once, as sent. Billing uses the stream usage. An error before the stream starts gets the normal JSON error. An error after the start ends the stream with an error event. Streams are never cached. yaegi-check now drives a streamed request under the interpreter.
This commit is contained in:
@@ -15,6 +15,9 @@ import (
|
||||
// later tasks' SSE streaming depends on Flush passing through.
|
||||
type statusTrackingWriter struct {
|
||||
http.ResponseWriter
|
||||
// sseError, when set, writes a mid-stream failure in the route's own SSE
|
||||
// error shape instead of the OpenAI one.
|
||||
sseError func(msg string)
|
||||
wroteHeader bool
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user