Documentation
¶
Overview ¶
Package openrouter implements llm.Client against OpenRouter (https://openrouter.ai). Streaming-first; tool-call assembly; 429/5xx retry at stream-start. The SSE parser is inlined here per ADR-022.
Index ¶
Constants ¶
const DefaultBaseURL = "https://openrouter.ai/api/v1"
DefaultBaseURL is OpenRouter's API root.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an OpenRouter implementation of llm.Client.
func (*Client) Stream ¶
Stream sends one chat-completions request and returns a channel of events. EventEnd is always the last event; the channel closes after EventEnd.
Retry happens only at stream-start: if the HTTP response is 429 or 5xx before any SSE bytes have been read, aikido closes the body and retries per the policy returned by retryPolicy(). Mid-stream errors do NOT retry — they propagate as EventError.
type Options ¶
type Options struct {
// APIKey is required.
APIKey string
// BaseURL overrides DefaultBaseURL. Useful for tests via httptest.Server.
BaseURL string
// HTTPClient overrides the default. Default: &http.Client{Timeout: 0}.
// Streams may be long-lived; callers wanting a wall-clock cap pass a
// context with deadline rather than configuring a client-level timeout.
HTTPClient *http.Client
// HTTPReferer is the optional OpenRouter ranking-attribution header.
HTTPReferer string
// XTitle is the optional OpenRouter ranking-attribution header.
XTitle string
// ProviderOrder is the optional `provider.order` routing preference.
// A single entry locks to one provider (allow_fallbacks=false); multiple
// entries form a fallback chain (allow_fallbacks=true). Matches the
// production pattern in asolabs/hub.
ProviderOrder []string
}
Options configure the OpenRouter Client.