api

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package api implements the LLM gateway against an HTTP endpoint that speaks either Anthropic's Messages API or OpenAI's Chat Completions API.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoAPIKey = errors.New("api: an API key is required")

ErrNoAPIKey is returned when no key is configured.

Functions

This section is empty.

Types

type AuthStyle

type AuthStyle string

AuthStyle selects how the API key is presented.

const (
	AuthStyleAnthropic AuthStyle = "x-api-key"
	AuthStyleBearer    AuthStyle = "bearer"
)

type Format added in v0.20.0

type Format string

Format is the request shape an endpoint speaks.

const (
	// FormatAnthropic posts to {base}/v1/messages.
	FormatAnthropic Format = "anthropic"
	// FormatOpenAI posts to {base}/chat/completions; base includes /v1.
	FormatOpenAI Format = "openai"
)

type Gateway

type Gateway struct {
	// contains filtered or unexported fields
}

Gateway is a direct-API LLM gateway.

func New

func New(o Options) (*Gateway, error)

New returns a gateway.

func (*Gateway) Complete

func (g *Gateway) Complete(ctx context.Context, r llm.Req) (llm.Res, error)

Complete implements llm.Gateway.

func (*Gateway) ModelFor

func (g *Gateway) ModelFor(c llm.ModelClass) string

ModelFor implements llm.Gateway.

type Options

type Options struct {
	BaseURL     string
	APIKey      string
	StrongModel string
	FastModel   string
	AuthStyle   AuthStyle
	// Format defaults to FormatAnthropic.
	Format Format
	// AuthHeader, when set, carries the key in that header instead of the
	// Authorization or x-api-key header. Azure and some proxies want one.
	AuthHeader string
	Cache      llm.Cache
	HTTPClient *http.Client
	MaxRetries int
	Sleep      func(time.Duration)
}

Options configures the gateway.

Jump to

Keyboard shortcuts

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