Documentation
¶
Overview ¶
Package openai implements the OpenAI-compatible HTTP surface: POST /v1/chat/completions and GET /v1/models, streaming and non-streaming.
Index ¶
Constants ¶
const MaxRequestBytes = 32 << 20 // 32 MiB
MaxRequestBytes caps the request body. A replayed conversation is the payload here, so the limit is generous, but not unbounded.
Variables ¶
This section is empty.
Functions ¶
func WriteError ¶
func WriteError(w http.ResponseWriter, err error)
WriteError renders err in OpenAI's error shape with the matching status.
Types ¶
type Handler ¶
type Handler struct {
Router *router.Router
Log *slog.Logger
// Heartbeat is how often a silent stream emits a keepalive comment. Zero
// disables keepalives; [New] starts it at [sse.DefaultHeartbeat].
Heartbeat time.Duration
// Now is injectable so tests get stable timestamps.
Now func() time.Time
}
Handler serves the OpenAI-compatible endpoints.
func (*Handler) ChatCompletions ¶
func (h *Handler) ChatCompletions(w http.ResponseWriter, r *http.Request)
ChatCompletions implements POST /v1/chat/completions.
func (*Handler) Model ¶
func (h *Handler) Model(w http.ResponseWriter, r *http.Request)
Model implements GET /v1/models/{model}.