v0.8.4

Interfaces and Router

Last updated

The Agent interfaces, the router factory, and what each provider package exports. Types live in github.com/pardnchiu/go-llm-router/core, which declares package llmrouter; the factory lives in core/router.

Interfaces

type Agent interface {
    Name() string
    Send(ctx context.Context, messages []Message, toolDefs []Tool, reasoning Reasoning, mode Mode) (*Output, int, error)
}

type StreamAgent interface {
    SendStream(ctx context.Context, messages []Message, toolDefs []Tool, reasoning Reasoning, mode Mode) (<-chan StreamEvent, error)
}

type ReasoningAgent interface {
    ReasoningLimits() (min, max Reasoning)
}

type ImageAgent interface {
    GenerateImage(ctx context.Context, prompt string, opts ImageOptions) (*ImageResult, error)
}

type STTAgent interface {
    Transcribe(ctx context.Context, audio []byte, opts STTOptions) (*STTResult, error)
}

type TTSAgent interface {
    Speak(ctx context.Context, text string, opts TTSOptions) (*TTSResult, error)
}

router

Symbol Signature Description
router.Config struct{ Name, APIKey string; Token any; BaseURL, AccountID, GatewayID string } Name is provider@model
router.New func(config Config) (llmrouter.Agent, error) Builds the agent for the prefix; an unknown prefix containing @ becomes compat[<prefix>]@<model>

Provider packages

Every provider package exposes the Prefix constant, New(llmrouter.Config) (*Agent, error), (*Agent).Name(), and Models(ctx, llmrouter.Config, llmrouter.ModelFilter) ([]string, error), except core/compat, which has no Prefix or Models.

Package Prefix Additional exports
core/claude claude@ —
core/openai openai@ ImageInput, ReadImageStream, ImageInstructions
core/gemini gemini@ ModelInfos; :generateContent wire types Content, Part, InlineData, FunctionCall, FunctionResponse, Output
core/grok grok@ RequestImage
core/grokOauth grok-oauth@ Usage
core/deepseek deepseek@ Usage
core/mistral mistral@ ModelInfos
core/nvidia nvidia@ —
core/ollamaCloud ollama-cloud@ Usage
core/openRouter openrouter@ Usage
core/cloudflare cloudflare@ —
core/compat compat@ / compat[name]@ —
core/copilot copilot@ Usage, ModelInfos
core/openaiCodex codex@ Usage

Shared wire helpers

Packages without a prefix that several adapters import.

Package Used by Exports
core/copilot/response (package copilotResponse) openai, codex, copilot, core/xai ConvertInput, ConvertTools, ConvertOutput; Responses API wire types Output, ToolCall
core/xai grok, grok-oauth ResponsesAPI (https://api.x.ai/v1/responses), BuildBody(ctx, model, messages, tools, effort string, fast bool) map[string]any, ParseSSEStream(label string, resp *http.Response) (*llmrouter.Output, error)

xai.BuildBody always requests a stream, so the non-streaming Send of both Grok adapters reads the SSE body with xai.ParseSSEStream and returns one assembled Output.

中文