openai

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openai implements the OpenAI-compatible HTTP surface: POST /v1/chat/completions and GET /v1/models, streaming and non-streaming.

Index

Constants

View Source
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 New

func New(r *router.Router, log *slog.Logger) *Handler

New builds a handler.

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}.

func (*Handler) Models

func (h *Handler) Models(w http.ResponseWriter, r *http.Request)

Models implements GET /v1/models: one row per backend being served.

func (*Handler) Routes

func (h *Handler) Routes(mux *http.ServeMux)

Routes registers the OpenAI endpoints on mux.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL