openaicompat

package
v1.20.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: GPL-3.0 Imports: 11 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 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

View Source
const (
	// Name is the registry key and the providers.<name> config block.
	Name = "openai-compatible"
)

Variables

This section is empty.

Functions

func Metadata

func Metadata() provider.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

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

func (c *Client) ContextWindow(string) int

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 (c *Client) DefaultModel() string

func (*Client) EstimateTokens

func (c *Client) EstimateTokens(s string) int

func (*Client) Name

func (c *Client) Name() string

func (*Client) Pricing

func (c *Client) Pricing(model string) provider.Pricing

Pricing returns the user-declared price for the model, zero when none was declared (cost is then reported as unknown by the CLI).

func (*Client) Review

func (c *Client) Review(ctx context.Context, req provider.Request) (provider.Response, error)

func (*Client) TestConnection

func (c *Client) TestConnection(ctx context.Context) error

Jump to

Keyboard shortcuts

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