llm

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProviderAnthropic  = "anthropic"
	ProviderOpenAI     = "openai"
	ProviderOpenRouter = "openrouter"
)

Variables

View Source
var ErrNoCatalogPrices = errors.New("provider does not publish catalog prices")

ErrNoCatalogPrices means the provider list-models API has no rate fields.

Functions

func APIKeyAAD

func APIKeyAAD(provider string) []byte

func DecryptAPIKey

func DecryptAPIKey(ctx context.Context, encryptor crypto.Encryptor, provider string, ciphertext []byte) (string, error)

func DecryptManagementKey

func DecryptManagementKey(ctx context.Context, encryptor crypto.Encryptor, provider string, ciphertext []byte) (string, error)

func EncryptAPIKey

func EncryptAPIKey(ctx context.Context, encryptor crypto.Encryptor, provider, apiKey string) ([]byte, error)

func EncryptManagementKey

func EncryptManagementKey(ctx context.Context, encryptor crypto.Encryptor, provider, managementKey string) ([]byte, error)

func ManagementKeyAAD

func ManagementKeyAAD(provider string) []byte

func SeedDevHostedOpenRouter

func SeedDevHostedOpenRouter(ctx context.Context, tx *gorm.DB, encryptor crypto.Encryptor, cfg config.DevHostedOpenRouterConfig) error

SeedDevHostedOpenRouter replaces the OpenRouter hosted-provider row and optionally sets the installation default model.

func SeedDevHostedOpenRouterFromEnv

func SeedDevHostedOpenRouterFromEnv(ctx context.Context, tx *gorm.DB, encryptor crypto.Encryptor) error

SeedDevHostedOpenRouterFromEnv writes the SuperPlane-hosted OpenRouter provider when the local development seed is complete. It is a no-op when the seed is unset. A half-filled flag returns an error.

func ValidateBaseURL

func ValidateBaseURL(raw string) error

Types

type CatalogPrice

type CatalogPrice struct {
	ID      string
	Pricing RawCatalogRate
}

CatalogPrice is one model id and the raw prices returned by its provider.

func ListCatalogPrices

func ListCatalogPrices(ctx context.Context, httpClient core.HTTPContext, provider string, creds Credentials) ([]CatalogPrice, error)

ListCatalogPrices fetches priced models for providers that publish catalog rates.

type Client

type Client interface {
	Provider() string
	ListModels(ctx context.Context) ([]Model, error)
	Complete(ctx context.Context, req CompleteRequest) (*CompleteResponse, error)
	Stream(ctx context.Context, req CompleteRequest, emit func(StreamEvent) error) error
}

Client is the shared provider surface for list, complete, and stream.

func New

func New(httpClient core.HTTPContext, provider string, creds Credentials) (Client, error)

New builds a client for one of the in-scope billing providers.

type CompleteRequest

type CompleteRequest struct {
	Model     string
	System    string
	Prompt    string
	MaxTokens int
}

CompleteRequest is a text completion. Prompt text is not stored on the ledger.

type CompleteResponse

type CompleteResponse struct {
	Text  string
	Model string
	Usage Usage
}

CompleteResponse is the model text plus normalized usage.

type Credentials

type Credentials struct {
	APIKey  string
	BaseURL string
}

Credentials are provider API credentials. Hosted catalog and later BYOK both supply this shape so the HTTP client stays funding-source agnostic.

type Model

type Model struct {
	ID string
}

Model is one id from a provider list-models response.

type RawCatalogRate

type RawCatalogRate struct {
	Prompt            string `json:"prompt"`
	Completion        string `json:"completion"`
	InputCacheRead    string `json:"input_cache_read"`
	InputCacheWrite   string `json:"input_cache_write"`
	InternalReasoning string `json:"internal_reasoning"`
}

RawCatalogRate contains provider prices in US dollars per token. Billing owns conversion into ledger rates.

type StreamEvent

type StreamEvent struct {
	Delta string
	Done  bool
	Usage *Usage
}

StreamEvent is one streamed text delta or the terminal usage snapshot.

type Usage

type Usage struct {
	InputTokens      int64
	OutputTokens     int64
	CacheReadTokens  int64
	CacheWriteTokens int64
	ReasoningTokens  int64
	TotalTokens      int64
	CostMicros       *int64
}

Usage is normalized token counts for one completion.

func (Usage) ToRecord

func (u Usage) ToRecord(provider, model string) core.UsageRecord

ToRecord maps usage onto the ledger call-site payload.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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