Documentation
¶
Overview ¶
Package openaicompat implements the Provider interface against any endpoint that speaks the OpenAI Chat Completions protocol (vLLM, LM Studio, OpenRouter, a corporate gateway, ...). It is configured purely through the providers.openai-compatible block: base_url and model are mandatory, everything else (key, prices, context window) is optional.
Like deepseek it reuses the openai-go SDK and keeps structured output prompt-driven: no response_format is ever sent, because json_schema support is uneven across OpenAI-compatible servers and an unsupporting one answers 400. JSON shape comes from the <response_format> prompt section plus the fence-salvage and repair-retry/degrade pipeline (ADR-0014, ADR-0031).
Index ¶
- Constants
- func Metadata() provider.Metadata
- func New(cfg config.ProviderConfig) (provider.Provider, error)
- type Client
- func (c *Client) ContextWindow(string) int
- func (c *Client) DefaultModel() string
- func (c *Client) EstimateTokens(s string) int
- func (c *Client) Name() string
- func (c *Client) Pricing(model string) provider.Pricing
- func (c *Client) Review(ctx context.Context, req provider.Request) (provider.Response, error)
- func (c *Client) TestConnection(ctx context.Context) error
Constants ¶
const (
// Name is the registry key and the providers.<name> config block.
Name = "openai-compatible"
)
Variables ¶
This section is empty.
Functions ¶
func Metadata ¶
Metadata describes openai-compatible without needing a credential or an endpoint (ADR-0039). Everything user-specific — model, base URL, prices, context window — is declared in config, so the static inventory carries no models, no default model and no fixed API-key variable (the key comes from providers.openai-compatible.api_key_env or api_key).
func New ¶
func New(cfg config.ProviderConfig) (provider.Provider, error)
New validates the config and builds a client. base_url and model have no defaults — there is no sensible one for "any compatible server".
cfg.APIKey is expected to be already resolved by the caller (api_key_env > api_key). An empty key means an anonymous endpoint: the Authorization header is removed entirely instead of being sent as "Bearer ".
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to a user-configured OpenAI-compatible endpoint.
func (*Client) ContextWindow ¶
ContextWindow returns the configured context_window, or 0 when it was not declared. Zero means "unknown": the token preflight then never blocks.
func (*Client) DefaultModel ¶
func (*Client) EstimateTokens ¶
func (*Client) Pricing ¶
Pricing returns the user-declared price for the model, zero when none was declared (cost is then reported as unknown by the CLI).