llm

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimateCost added in v0.2.0

func EstimateCost(provider, model string, inputTokens, outputTokens int64) float64

EstimateCost returns a conservative per-call USD estimate. Unknown models use the documented fallback price so observability remains useful without exposing provider credentials or requiring a remote price lookup.

func ProviderDomain added in v0.2.0

func ProviderDomain(provider string) string

ProviderDomain returns the egress domain (hostname) for a given provider. Returns empty string for unknown providers.

func ProviderDomains added in v0.2.0

func ProviderDomains() map[string]string

ProviderDomains returns a map of all provider → domain mappings.

func SetTestEndpoints

func SetTestEndpoints(openAI, anthropic, xai string) func()

SetTestEndpoints overrides provider endpoints for testing. Returns a restore function.

func SupportedProviders

func SupportedProviders() []string

SupportedProviders returns the list of supported provider names.

Types

type LLMResult

type LLMResult struct {
	Text         string `json:"text"`
	Tokens       int64  `json:"tokens"`
	Model        string `json:"model,omitempty"`
	InputTokens  int64  `json:"input_tokens,omitempty"`
	OutputTokens int64  `json:"output_tokens,omitempty"`
}

LLMResult holds the parsed response from an LLM provider call.

type ProviderAdapter

type ProviderAdapter interface {
	// BuildRequest creates an HTTP request for the LLM provider.
	// credentialValue is the API key (NEVER logged or included in errors).
	BuildRequest(ctx context.Context, model, prompt string, credentialValue string, maxTokens ...int) (*http.Request, error)
	// ParseResponse extracts text and token count from the provider response body.
	ParseResponse(statusCode int, body []byte) (*LLMResult, error)
	// Endpoint returns the provider's API endpoint URL (for logging/audit).
	Endpoint() string
	// AuthHeader returns the header name used for the API key (e.g. "Authorization", "x-api-key").
	AuthHeader() string
	// Name returns the provider name (e.g. "openai", "anthropic", "xiai").
	Name() string
}

ProviderAdapter maps an LLM provider to its API endpoint, auth header, request body format, and response parser. Used by the harness to route agent.llm() calls as credentialed HTTP egress (Option B unified egress).

func GetAdapter

func GetAdapter(provider string) ProviderAdapter

GetAdapter returns the adapter for the given provider name. Supported: "openrouter", "openai", "anthropic", "xai"/"xiai", "nous". Returns nil for unknown providers.

Jump to

Keyboard shortcuts

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