Documentation
¶
Overview ¶
Package sigma provides provider-neutral model calls for Go applications.
The root package owns stable request, response, model, registry, stream, image, tool, reasoning, persistence, and error types. Provider-specific HTTP and cloud SDK behavior lives in provider subpackages, which register implementations on a Registry.
Clients use a clone of the package-level default registry unless configured with WithRegistry. The default registry is intended for ordinary application code that wants built-in metadata. Provider packages still need to be imported and registered before runtime dispatch. Use NewRegistry with WithRegistry when tests, local endpoints, or applications need isolated custom providers and models.
HTTP provider adapters share the root retry policy: no retries by default, optional per-request timeouts through context, retries for transient network failures, 429, and 5xx responses, and conservative streaming retries only before a response body is consumed.
Index ¶
- Constants
- Variables
- func AccountUsage(model Model, usage Usage, opts ...UsageAccountingOption) (Usage, Cost)
- func ApplySuppressedHeaders(headers http.Header, opts Options)
- func CleanupSessionResources(sessionID string) error
- func CombineEmbeddingVectors(vectors [][]float32, weights []int) ([]float32, error)
- func CompleteText(ctx context.Context, model Model, prompt string, opts ...Option) (string, error)
- func ContextWithRequestTimeout(ctx context.Context, opts Options) (context.Context, context.CancelFunc)
- func CosineSimilarity(a, b []float32) (float64, error)
- func DoHTTPWithRetry(ctx context.Context, client *http.Client, opts Options, ...) (*http.Response, error)
- func DotProduct(a, b []float32) (float64, error)
- func EstimateContentTokens(blocks []ContentBlock) int
- func EstimateMessageTokens(message Message) int
- func EstimateTextTokens(text string) int
- func IsContextOverflow(message AssistantMessage, contextWindow int) bool
- func MarshalRequest(req Request) ([]byte, error)
- func MaxTokensForContext(model Model, req Request, requestedMaxTokens int) int
- func NewImageStream(ctx context.Context) (*ImageStream, ImageStreamWriter)
- func NewStream(ctx context.Context) (*Stream, StreamWriter)
- func NormalizeEmbeddingNewlines(inputs []string) []string
- func NormalizeEmbeddingVector(vector []float32) ([]float32, error)
- func ParseRetryAfter(value string, now time.Time) time.Duration
- func RegisterDefaultEmbeddingModel(model EmbeddingModel, opts ...RegisterOption) error
- func RegisterDefaultEmbeddingProvider(id ProviderID, provider EmbeddingProvider, opts ...RegisterOption) error
- func RegisterDefaultImageModel(model ImageModel, opts ...RegisterOption) error
- func RegisterDefaultImageProvider(id ProviderID, provider ImageProvider, opts ...RegisterOption) error
- func RegisterDefaultModel(model Model, opts ...RegisterOption) error
- func RegisterDefaultProviderAuth(id ProviderID, auth ProviderAuth, opts ...RegisterOption) error
- func RegisterDefaultTextModelSource(provider ProviderID, source TextModelSource, opts ...RegisterOption) error
- func RegisterDefaultTextProvider(id ProviderID, provider TextProvider, opts ...RegisterOption) error
- func RegisterEmbeddingModel(registry *Registry, model EmbeddingModel, opts ...RegisterOption) error
- func RegisterEmbeddingModelSource(registry *Registry, provider ProviderID, source EmbeddingModelSource, ...) error
- func RegisterImageModelSource(registry *Registry, provider ProviderID, source ImageModelSource, ...) error
- func RegisterModel(registry *Registry, model Model, opts ...RegisterOption) error
- func RegisterProvider(registry *Registry, id ProviderID, provider TextProvider, ...) error
- func RegisterProviderAuth(registry *Registry, provider ProviderID, auth ProviderAuth, ...) error
- func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
- func RegisterTextModelSource(registry *Registry, provider ProviderID, source TextModelSource, ...) error
- func ResolveAuthForRequest(ctx context.Context, model Model, opts Options) (Options, Credential, error)
- func RetryAfter(header http.Header) time.Duration
- func RetryableNetworkError(err error) bool
- func RetryableStatusCode(status int) bool
- func RunEmbeddingPayloadDebugHooks(ctx context.Context, opts Options, provider ProviderID, api EmbeddingAPI, ...) error
- func RunImagePayloadDebugHooks(ctx context.Context, opts Options, provider ProviderID, api ImageAPI, ...) error
- func RunTextPayloadDebugHooks(ctx context.Context, opts Options, provider ProviderID, api API, model ModelID, ...) error
- func ToolErrorMessage(call ToolCall, err error) string
- func ValidateModelRef(ref ModelRef) error
- func ValidateRequest(req Request) error
- func ValidateToolCall(tools []Tool, call ToolCall) (map[string]any, error)
- func ValidateToolCallWithOptions(tools []Tool, call ToolCall, options ToolValidationOptions) (map[string]any, error)
- type API
- type APIKeyAuth
- type APIKeyAuthResolver
- type AnthropicCompatSupport
- type AnthropicMessagesCompat
- type AnthropicOptions
- type AnthropicThinkingDisplay
- type AnthropicThinkingFormat
- type AnthropicToolChoice
- type AnthropicToolChoiceType
- type AssistantImages
- type AssistantMessage
- type AuthResolution
- type AuthResolutionResolver
- type AuthResolver
- type AuthResolverFunc
- type AzureOpenAIResponsesConfig
- type BedrockOptions
- type BedrockThinkingDisplay
- type BedrockToolChoice
- type BedrockToolChoiceType
- type CacheRetention
- type CachedTextModelSource
- type ChainAuthResolver
- type Client
- func (c *Client) Complete(ctx context.Context, model Model, req Request, opts ...Option) (AssistantMessage, error)
- func (c *Client) CompleteText(ctx context.Context, model Model, prompt string, opts ...Option) (string, error)
- func (c *Client) Embed(ctx context.Context, model EmbeddingModel, req EmbeddingRequest, ...) (Embeddings, error)
- func (c *Client) EmbedBatch(ctx context.Context, model EmbeddingModel, req EmbeddingRequest, ...) (EmbeddingBatchResult, error)
- func (c *Client) EmbeddingModels() []EmbeddingModel
- func (c *Client) GenerateImages(ctx context.Context, model ImageModel, req ImageRequest, opts ...ImageOption) (AssistantImages, error)
- func (c *Client) GetEmbeddingModel(provider ProviderID, id ModelID) (EmbeddingModel, bool)
- func (c *Client) GetImageModel(provider ProviderID, id ModelID) (ImageModel, bool)
- func (c *Client) GetModel(provider ProviderID, id ModelID) (Model, bool)
- func (c *Client) ImageModels() []ImageModel
- func (c *Client) Models(filters ...ModelFilter) []Model
- func (c *Client) RefreshEmbeddingModels(ctx context.Context, providers ...ProviderID) error
- func (c *Client) RefreshImageModels(ctx context.Context, providers ...ProviderID) error
- func (c *Client) RefreshTextModels(ctx context.Context, providers ...ProviderID) error
- func (c *Client) Registry() *Registry
- func (c *Client) RestoreTextModels(ctx context.Context, providers ...ProviderID) error
- func (c *Client) Stream(ctx context.Context, model Model, req Request, opts ...Option) *Stream
- func (c *Client) StreamImages(ctx context.Context, model ImageModel, req ImageRequest, opts ...ImageOption) *ImageStream
- type ClientEmbeddingEmbedder
- type ClientOption
- func WithAuthResolver(resolver AuthResolver) ClientOption
- func WithCredentialStore(store CredentialStore) ClientOption
- func WithDefaultHeader(key, value string) ClientOption
- func WithDefaultHeaders(headers map[string]string) ClientOption
- func WithDefaultOptions(opts ...Option) ClientOption
- func WithHTTPClient(httpClient *http.Client) ClientOption
- func WithRegistry(registry *Registry) ClientOption
- func WithStoredProviderAuth() ClientOption
- type CloudCredentialProvider
- type ContentBlock
- func DocumentBase64(mimeType string, filename string, data string) ContentBlock
- func DocumentFileID(mimeType string, filename string, fileID string) ContentBlock
- func DocumentURL(mimeType string, filename string, url string) ContentBlock
- func ImageBase64(mimeType string, data string) ContentBlock
- func ImageURL(mimeType string, url string) ContentBlock
- func Text(text string) ContentBlock
- func Thinking(text string, signature string) ContentBlock
- func ToolCallBlock(id string, name string, arguments any) ContentBlock
- type ContentBlockType
- type Cost
- type Credential
- type CredentialModifyFunc
- type CredentialStore
- type CredentialType
- type CredentialUnavailableError
- type Diagnostic
- type Embedding
- type EmbeddingAPI
- type EmbeddingAttempt
- type EmbeddingBatchConfig
- type EmbeddingBatchPhase
- type EmbeddingBatchProgress
- type EmbeddingBatchResult
- type EmbeddingBatchSummary
- type EmbeddingBatchTraceEvent
- type EmbeddingCache
- type EmbeddingCacheKey
- type EmbeddingEmbedder
- type EmbeddingEmbedderConfig
- type EmbeddingInputType
- type EmbeddingModel
- type EmbeddingModelSource
- type EmbeddingModelSourceFunc
- type EmbeddingOption
- func WithEmbeddingAPIKey(apiKey string) EmbeddingOption
- func WithEmbeddingAuthResolver(resolver AuthResolver) EmbeddingOption
- func WithEmbeddingHTTPClient(httpClient *http.Client) EmbeddingOption
- func WithEmbeddingHeader(key, value string) EmbeddingOption
- func WithEmbeddingHeaders(headers map[string]string) EmbeddingOption
- func WithEmbeddingMaxRetries(maxRetries int) EmbeddingOption
- func WithEmbeddingMaxRetryDelay(maxRetryDelay time.Duration) EmbeddingOption
- func WithEmbeddingMetadata(metadata map[string]any) EmbeddingOption
- func WithEmbeddingMetadataValue(key string, value any) EmbeddingOption
- func WithEmbeddingPayloadDebugHook(hook EmbeddingPayloadDebugHook) EmbeddingOption
- func WithEmbeddingProviderAuthResolver(provider ProviderID, resolver AuthResolver) EmbeddingOption
- func WithEmbeddingProviderOption(provider ProviderID, key string, value any) EmbeddingOption
- func WithEmbeddingProviderOptions(provider ProviderID, values map[string]any) EmbeddingOption
- func WithEmbeddingResponseDebugHook(hook EmbeddingResponseDebugHook) EmbeddingOption
- func WithEmbeddingSuppressedHeader(key string) EmbeddingOption
- func WithEmbeddingSuppressedHeaders(keys ...string) EmbeddingOption
- func WithEmbeddingTimeout(timeout time.Duration) EmbeddingOption
- type EmbeddingPayloadDebug
- type EmbeddingPayloadDebugHook
- type EmbeddingProvider
- type EmbeddingRequest
- type EmbeddingResponseDebug
- type EmbeddingResponseDebugHook
- type EmbeddingScore
- type EmbeddingSplitPolicy
- type Embeddings
- type EnvironmentAuthResolver
- type Error
- type ErrorClass
- type ErrorClassification
- type ErrorCode
- type Event
- type EventKind
- type GenerationError
- type GoogleOptions
- type HTTPAttempt
- type HTTPResponseHook
- func EmbeddingResponseDebugHTTPHook(ctx context.Context, opts Options, provider ProviderID, api EmbeddingAPI, ...) HTTPResponseHook
- func ImageResponseDebugHTTPHook(ctx context.Context, opts Options, provider ProviderID, api ImageAPI, ...) HTTPResponseHook
- func TextResponseDebugHTTPHook(ctx context.Context, opts Options, provider ProviderID, api API, model ModelID) HTTPResponseHook
- type HandoffChange
- type HandoffChangeKind
- type HandoffMessagesResult
- type HandoffOption
- type HandoffReport
- type HandoffResult
- type ImageAPI
- type ImageError
- type ImageEvent
- type ImageEventKind
- type ImageInput
- type ImageModel
- type ImageModelSource
- type ImageModelSourceFunc
- type ImageOperation
- type ImageOption
- func WithImageAPIKey(apiKey string) ImageOption
- func WithImageAuthResolver(resolver AuthResolver) ImageOption
- func WithImageHTTPClient(httpClient *http.Client) ImageOption
- func WithImageHeader(key, value string) ImageOption
- func WithImageHeaders(headers map[string]string) ImageOption
- func WithImageMaxRetries(maxRetries int) ImageOption
- func WithImageMaxRetryDelay(maxRetryDelay time.Duration) ImageOption
- func WithImageMetadata(metadata map[string]any) ImageOption
- func WithImageMetadataValue(key string, value any) ImageOption
- func WithImagePayloadDebugHook(hook ImagePayloadDebugHook) ImageOption
- func WithImageProviderAuthResolver(provider ProviderID, resolver AuthResolver) ImageOption
- func WithImageProviderOption(provider ProviderID, key string, value any) ImageOption
- func WithImageProviderOptions(provider ProviderID, values map[string]any) ImageOption
- func WithImageResponseDebugHook(hook ImageResponseDebugHook) ImageOption
- func WithImageSuppressedHeader(key string) ImageOption
- func WithImageSuppressedHeaders(keys ...string) ImageOption
- func WithImageTimeout(timeout time.Duration) ImageOption
- type ImagePayloadDebug
- type ImagePayloadDebugHook
- type ImageProvider
- type ImageQuality
- type ImageRequest
- type ImageResponseDebug
- type ImageResponseDebugHook
- type ImageSize
- type ImageStream
- type ImageStreamWriter
- type InMemoryCredentialStore
- func (s *InMemoryCredentialStore) DeleteCredential(_ context.Context, provider ProviderID) error
- func (s *InMemoryCredentialStore) ModifyCredential(ctx context.Context, provider ProviderID, fn CredentialModifyFunc) (StoredCredential, bool, error)
- func (s *InMemoryCredentialStore) ReadCredential(_ context.Context, provider ProviderID) (StoredCredential, bool, error)
- type InMemoryRetrievalIndex
- func (i *InMemoryRetrievalIndex) AddChunks(ctx context.Context, chunks []RetrievalChunk) error
- func (i *InMemoryRetrievalIndex) AddDocuments(ctx context.Context, docs []RetrievalDocument) error
- func (i *InMemoryRetrievalIndex) Search(ctx context.Context, query string, limit int) ([]RetrievalResult, error)
- type InMemoryRetrievalIndexConfig
- type Message
- type MistralOptions
- type MistralToolChoice
- type MistralToolChoiceType
- type Model
- func (model Model) ProviderThinkingLevel(level ThinkingLevel) (string, bool)
- func (model Model) SupportsDocuments() bool
- func (model Model) SupportsImages() bool
- func (model Model) SupportsInput(kind ContentBlockType) bool
- func (model Model) SupportsReasoning() bool
- func (model Model) SupportsThinkingLevel(level ThinkingLevel) bool
- type ModelCostTier
- type ModelFilter
- type ModelID
- type ModelRef
- type OAuthAuth
- type OAuthCredentialFunc
- type OAuthRefreshFunc
- type OAuthTokenProvider
- type OAuthTokenProviderFunc
- type OpenAICodexResponsesConfig
- type OpenAICompatSupport
- type OpenAICompatibleEmbeddingModelConfig
- type OpenAICompatibleModelConfig
- type OpenAICompletionsCacheControlFormat
- type OpenAICompletionsCompat
- type OpenAICompletionsMaxTokensField
- type OpenAICompletionsReasoningFormat
- type OpenAIGrammar
- type OpenAIGrammarSyntax
- type OpenAIOptions
- type OpenAIResponsesCompat
- type OpenAIResponsesSessionAffinityFormat
- type OpenRouterRoutingPreference
- type Option
- func WithAPIKey(apiKey string) Option
- func WithAnthropicOptions(anthropicOptions AnthropicOptions) Option
- func WithAutomaticMaxTokensForContext(enabled bool) Option
- func WithBedrockOptions(bedrockOptions BedrockOptions) Option
- func WithCacheRetention(retention CacheRetention) Option
- func WithGoogleOptions(googleOptions GoogleOptions) Option
- func WithHeader(key, value string) Option
- func WithHeaders(headers map[string]string) Option
- func WithJSONOutput() Option
- func WithJSONSchemaOutput(name string, schema any, strict bool) Option
- func WithMaxRetries(maxRetries int) Option
- func WithMaxRetryDelay(maxRetryDelay time.Duration) Option
- func WithMaxTokens(maxTokens int) Option
- func WithMaxTokensForContext(model Model, req Request, requestedMaxTokens int) Option
- func WithMetadata(metadata map[string]any) Option
- func WithMetadataValue(key string, value any) Option
- func WithMistralOptions(mistralOptions MistralOptions) Option
- func WithOpenAIOptions(openAIOptions OpenAIOptions) Option
- func WithProviderAuthResolver(provider ProviderID, resolver AuthResolver) Option
- func WithProviderOption(provider ProviderID, key string, value any) Option
- func WithProviderOptions(provider ProviderID, values map[string]any) Option
- func WithReasoningBudgetForContext(model Model, req Request, level ThinkingLevel, requestedMaxTokens int) Option
- func WithReasoningLevel(level ThinkingLevel) Option
- func WithRequestHTTPClient(httpClient *http.Client) Option
- func WithSessionID(sessionID string) Option
- func WithStructuredOutput(output StructuredOutput) Option
- func WithSuppressedHeader(key string) Option
- func WithSuppressedHeaders(keys ...string) Option
- func WithTemperature(temperature float64) Option
- func WithTextPayloadDebugHook(hook TextPayloadDebugHook) Option
- func WithTextResponseDebugHook(hook TextResponseDebugHook) Option
- func WithThinkingBudgetTokens(tokens int) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTopLogprobs(top int) Option
- func WithTransport(transport Transport) Option
- type Options
- type PartialToolCall
- type ProviderAuth
- type ProviderAuthInfo
- type ProviderError
- type ProviderID
- type ProviderInfo
- type ReasoningBudget
- type RegisterOption
- type Registry
- func (r *Registry) Clone() *Registry
- func (r *Registry) EmbeddingModel(provider ProviderID, id ModelID) (EmbeddingModel, bool)
- func (r *Registry) EmbeddingProvider(id ProviderID) (EmbeddingProvider, bool)
- func (r *Registry) ImageModel(provider ProviderID, id ModelID) (ImageModel, bool)
- func (r *Registry) ImageProvider(id ProviderID) (ImageProvider, bool)
- func (r *Registry) ListEmbeddingModels() []EmbeddingModel
- func (r *Registry) ListImageModels() []ImageModel
- func (r *Registry) ListModels() []Model
- func (r *Registry) ListProviderAuths() []ProviderAuthInfo
- func (r *Registry) ListProviders() []ProviderInfo
- func (r *Registry) Model(provider ProviderID, id ModelID) (Model, bool)
- func (r *Registry) ProviderAuth(provider ProviderID) (ProviderAuth, bool)
- func (r *Registry) RefreshEmbeddingModels(ctx context.Context, providers ...ProviderID) error
- func (r *Registry) RefreshImageModels(ctx context.Context, providers ...ProviderID) error
- func (r *Registry) RefreshTextModels(ctx context.Context, providers ...ProviderID) error
- func (r *Registry) RegisterEmbeddingModel(model EmbeddingModel, opts ...RegisterOption) error
- func (r *Registry) RegisterEmbeddingModelSource(provider ProviderID, source EmbeddingModelSource, opts ...RegisterOption) error
- func (r *Registry) RegisterEmbeddingProvider(id ProviderID, provider EmbeddingProvider, opts ...RegisterOption) error
- func (r *Registry) RegisterImageModel(model ImageModel, opts ...RegisterOption) error
- func (r *Registry) RegisterImageModelSource(provider ProviderID, source ImageModelSource, opts ...RegisterOption) error
- func (r *Registry) RegisterImageProvider(id ProviderID, provider ImageProvider, opts ...RegisterOption) error
- func (r *Registry) RegisterModel(model Model, opts ...RegisterOption) error
- func (r *Registry) RegisterProviderAuth(provider ProviderID, auth ProviderAuth, opts ...RegisterOption) error
- func (r *Registry) RegisterTextModelSource(provider ProviderID, source TextModelSource, opts ...RegisterOption) error
- func (r *Registry) RegisterTextProvider(id ProviderID, provider TextProvider, opts ...RegisterOption) error
- func (r *Registry) RestoreTextModels(ctx context.Context, providers ...ProviderID) error
- func (r *Registry) Snapshot() RegistrySnapshot
- func (r *Registry) TextProvider(id ProviderID) (TextProvider, bool)
- type RegistrySnapshot
- type Request
- type ResultCitation
- type ResultSource
- type RetrievalChunk
- type RetrievalDocument
- type RetrievalResult
- type RetrievalSplitterConfig
- type RetryHint
- type Role
- type RouteAction
- type RouteAdvice
- type RouteClassification
- type RouteDecision
- type RouteOption
- func WithRouteBoundaries(simpleStandard float64, standardComplex float64, complexReasoning float64) RouteOption
- func WithRouteExclusions(refs ...ModelRef) RouteOption
- func WithRouteModelLookup(lookup func(ModelRef) (Model, bool)) RouteOption
- func WithRouteWeight(dimension string, weight float64) RouteOption
- type RoutePolicy
- type RouteSignal
- type RouteTier
- type Schema
- type SessionResourceCleanup
- type StopReason
- type StoredCredential
- type StoredCredentialAuthResolver
- type Stream
- type StreamWriter
- type StreamingImageProvider
- type StructuredOutput
- type StructuredOutputType
- type TextModelSource
- type TextModelSourceFunc
- type TextPayloadDebug
- type TextPayloadDebugHook
- type TextProvider
- type TextResponseDebug
- type TextResponseDebugHook
- type ThinkingLevel
- type TokenEstimate
- type Tool
- type ToolCall
- type ToolValidationError
- type ToolValidationOptions
- type Transport
- type Usage
- type UsageAccountingOption
- type VercelAIGatewayRoutingPreference
Examples ¶
Constants ¶
const ( // MetadataAPIKeyEnvVar names one API-key environment variable in model metadata. MetadataAPIKeyEnvVar = "apiKeyEnvVar" // MetadataAPIKeyEnvVars names ordered API-key environment variables in model metadata. MetadataAPIKeyEnvVars = "apiKeyEnvVars" )
const ( // ImageInputText identifies text input for image APIs. ImageInputText = "text" // ImageInputImage identifies image input or output for image APIs. ImageInputImage = "image" // ImageSourceBase64 identifies inline base64 image data. ImageSourceBase64 = "base64" // ImageSourceURL identifies URL-backed image data. ImageSourceURL = "url" // ImageSourceFileID identifies an already-uploaded provider file reference. ImageSourceFileID = "file_id" )
const ( // MetadataOpenAICompatible marks a model as caller-registered // OpenAI-compatible metadata that should be validated as runnable. MetadataOpenAICompatible = "openAICompatible" // MetadataOpenAICompatibleBaseURL stores the /v1-compatible endpoint for a // caller-registered OpenAI-compatible model. MetadataOpenAICompatibleBaseURL = "openAICompatibleBaseURL" // MetadataOpenAICompatibleHeaders stores model-scoped HTTP headers for a // caller-registered OpenAI-compatible model. MetadataOpenAICompatibleHeaders = "openAICompatibleHeaders" )
const ( // DefaultMaxRetries is the default number of retries after the first HTTP // request attempt. DefaultMaxRetries = 0 // DefaultRetryBaseDelay is the base delay used between retries when a // provider does not return Retry-After. DefaultRetryBaseDelay = 100 * time.Millisecond // DefaultMaxRetryDelay caps retry waits, including Retry-After. DefaultMaxRetryDelay = 2 * time.Second )
const ( RouteDimensionReasoningMarkers = "reasoningMarkers" RouteDimensionTechnicalTerms = "technicalTerms" RouteDimensionSimpleIndicators = "simpleIndicators" RouteDimensionCodePresence = "codePresence" RouteDimensionMultiStepPatterns = "multiStepPatterns" RouteDimensionQuestionComplexity = "questionComplexity" RouteDimensionTokenCount = "tokenCount" )
Classifier dimension names accepted by WithRouteWeight.
Variables ¶
var ( // ErrEmbeddingVectorDimensionMismatch reports vectors with incompatible dimensions. ErrEmbeddingVectorDimensionMismatch = errors.New("embedding vector dimensions do not match") // ErrEmbeddingVectorZeroNorm reports a vector that cannot be normalized. ErrEmbeddingVectorZeroNorm = errors.New("embedding vector norm is zero") // ErrEmbeddingVectorWeightMismatch reports a weight list that does not match the vector list. ErrEmbeddingVectorWeightMismatch = errors.New("embedding vector weights do not match vectors") // ErrEmbeddingVectorZeroWeight reports a weighted operation with no effective weight. ErrEmbeddingVectorZeroWeight = errors.New("embedding vector weight sum is zero") )
var ( // ErrNoProvider indicates no provider is registered for a model. ErrNoProvider = errors.New("provider unavailable") // ErrModelNotFound indicates no model metadata is registered for a model. ErrModelNotFound = errors.New("model not found") ErrCredentialUnavailable = errors.New("credential unavailable") // ErrAborted indicates generation stopped because the request was canceled. ErrAborted = errors.New("generation aborted") // ErrContextOverflow indicates a request exceeded the provider context limit. ErrContextOverflow = errors.New("context overflow") // ErrToolValidation indicates a tool definition or tool call failed validation. ErrToolValidation = errors.New("tool validation failed") // ErrProviderResponse indicates the provider returned an error response. ErrProviderResponse = errors.New("provider response error") // ErrInvalidOptions indicates request options failed local validation. ErrInvalidOptions = errors.New("invalid options") // ErrRetryAfterExceedsMaxDelay indicates a provider asked for a retry // delay longer than the configured cap. ErrRetryAfterExceedsMaxDelay = errors.New("retry-after exceeds max retry delay") )
var ErrDebugHook = errors.New("debug hook failed")
ErrDebugHook indicates a caller-provided debug hook failed.
var ErrNoRouteCandidates = errors.New("no route candidates")
ErrNoRouteCandidates reports that a routing policy has no usable candidate for the classified tier or any other tier.
Functions ¶
func AccountUsage ¶ added in v0.6.0
func AccountUsage(model Model, usage Usage, opts ...UsageAccountingOption) (Usage, Cost)
AccountUsage stamps usage with model identity, preserves raw provider usage, and calculates Sigma's estimated cost from model metadata.
func ApplySuppressedHeaders ¶ added in v0.6.0
ApplySuppressedHeaders removes request headers configured with WithSuppressedHeader or WithSuppressedHeaders.
func CleanupSessionResources ¶ added in v0.6.0
CleanupSessionResources releases registered provider-owned session resources. Passing an empty sessionID releases all registered session resources.
func CombineEmbeddingVectors ¶ added in v0.3.0
CombineEmbeddingVectors returns a normalized weighted average of embedding vectors.
func CompleteText ¶
CompleteText is a text-only helper using the default registry.
It returns an error if the final assistant message contains non-text content, so tool calls and thinking blocks are not silently discarded.
func ContextWithRequestTimeout ¶
func ContextWithRequestTimeout(ctx context.Context, opts Options) (context.Context, context.CancelFunc)
ContextWithRequestTimeout applies Options.Timeout to ctx. The returned cancel function must be called when the provider request is complete.
func CosineSimilarity ¶ added in v0.3.0
CosineSimilarity calculates cosine similarity for two embedding vectors.
func DoHTTPWithRetry ¶
func DoHTTPWithRetry( ctx context.Context, client *http.Client, opts Options, newRequest func(context.Context) (*http.Request, error), providerError func(*http.Response) *ProviderError, hooks ...HTTPResponseHook, ) (*http.Response, error)
DoHTTPWithRetry sends a request with sigma's shared HTTP retry policy.
The returned response body belongs to the caller and has not been consumed by the retry helper. Bodies from retry attempts are closed before the next request attempt.
func DotProduct ¶ added in v0.3.0
DotProduct calculates the dot product for two embedding vectors.
func EstimateContentTokens ¶ added in v0.6.0
func EstimateContentTokens(blocks []ContentBlock) int
EstimateContentTokens returns a deterministic approximate token count for message content blocks.
func EstimateMessageTokens ¶ added in v0.6.0
EstimateMessageTokens returns a deterministic approximate token count for a persisted message.
func EstimateTextTokens ¶ added in v0.6.0
EstimateTextTokens returns a deterministic approximate token count for text.
func IsContextOverflow ¶ added in v0.5.0
func IsContextOverflow(message AssistantMessage, contextWindow int) bool
IsContextOverflow reports whether a final assistant message indicates that a request exceeded the model context window.
Error messages are detected from safe provider diagnostics. Usage-based detection requires a positive contextWindow supplied by the caller.
func MarshalRequest ¶
MarshalRequest serializes req as the public Request JSON shape.
func MaxTokensForContext ¶ added in v0.6.0
MaxTokensForContext returns an opt-in max output token cap for req and model.
requestedMaxTokens is used when positive, clamped to model.MaxOutputTokens when the catalog reports one; otherwise model.MaxOutputTokens is used. A zero return means no usable output cap was available. The helper uses EstimateRequestTokens and a fixed safety margin; it does not call provider tokenizers or affect dispatch unless the caller applies the returned value.
func NewImageStream ¶ added in v0.3.0
func NewImageStream(ctx context.Context) (*ImageStream, ImageStreamWriter)
NewImageStream constructs an image stream and its provider-side writer.
func NewStream ¶
func NewStream(ctx context.Context) (*Stream, StreamWriter)
NewStream constructs a stream and its provider-side writer.
func NormalizeEmbeddingNewlines ¶ added in v0.3.0
NormalizeEmbeddingNewlines returns a copy of inputs with newlines replaced by spaces.
func NormalizeEmbeddingVector ¶ added in v0.3.0
NormalizeEmbeddingVector returns a unit-length copy of vector.
func ParseRetryAfter ¶
ParseRetryAfter parses Retry-After seconds or HTTP-date values relative to now.
func RegisterDefaultEmbeddingModel ¶ added in v0.3.0
func RegisterDefaultEmbeddingModel(model EmbeddingModel, opts ...RegisterOption) error
RegisterDefaultEmbeddingModel registers an embedding model on the default registry.
func RegisterDefaultEmbeddingProvider ¶ added in v0.3.0
func RegisterDefaultEmbeddingProvider(id ProviderID, provider EmbeddingProvider, opts ...RegisterOption) error
RegisterDefaultEmbeddingProvider registers an embedding provider on the default registry.
func RegisterDefaultImageModel ¶
func RegisterDefaultImageModel(model ImageModel, opts ...RegisterOption) error
RegisterDefaultImageModel registers an image model on the default registry.
func RegisterDefaultImageProvider ¶
func RegisterDefaultImageProvider(id ProviderID, provider ImageProvider, opts ...RegisterOption) error
RegisterDefaultImageProvider registers an image provider on the default registry.
func RegisterDefaultModel ¶
func RegisterDefaultModel(model Model, opts ...RegisterOption) error
RegisterDefaultModel registers a text model on the default registry.
func RegisterDefaultProviderAuth ¶ added in v0.6.0
func RegisterDefaultProviderAuth(id ProviderID, auth ProviderAuth, opts ...RegisterOption) error
RegisterDefaultProviderAuth registers provider auth on the default registry.
func RegisterDefaultTextModelSource ¶ added in v0.7.0
func RegisterDefaultTextModelSource(provider ProviderID, source TextModelSource, opts ...RegisterOption) error
RegisterDefaultTextModelSource registers a runtime text model source on the default registry.
func RegisterDefaultTextProvider ¶
func RegisterDefaultTextProvider(id ProviderID, provider TextProvider, opts ...RegisterOption) error
RegisterDefaultTextProvider registers a text provider on the default registry.
func RegisterEmbeddingModel ¶ added in v0.3.0
func RegisterEmbeddingModel(registry *Registry, model EmbeddingModel, opts ...RegisterOption) error
RegisterEmbeddingModel registers embedding model metadata on registry.
func RegisterEmbeddingModelSource ¶ added in v0.6.0
func RegisterEmbeddingModelSource(registry *Registry, provider ProviderID, source EmbeddingModelSource, opts ...RegisterOption) error
RegisterEmbeddingModelSource registers a runtime embedding model source on registry.
func RegisterImageModelSource ¶ added in v0.6.0
func RegisterImageModelSource(registry *Registry, provider ProviderID, source ImageModelSource, opts ...RegisterOption) error
RegisterImageModelSource registers a runtime image model source on registry.
func RegisterModel ¶
func RegisterModel(registry *Registry, model Model, opts ...RegisterOption) error
RegisterModel registers text model metadata on registry.
func RegisterProvider ¶
func RegisterProvider(registry *Registry, id ProviderID, provider TextProvider, opts ...RegisterOption) error
RegisterProvider registers a text provider on registry.
func RegisterProviderAuth ¶ added in v0.6.0
func RegisterProviderAuth(registry *Registry, provider ProviderID, auth ProviderAuth, opts ...RegisterOption) error
RegisterProviderAuth registers auth metadata on registry.
func RegisterSessionResourceCleanup ¶ added in v0.6.0
func RegisterSessionResourceCleanup(cleanup SessionResourceCleanup) func()
RegisterSessionResourceCleanup registers cleanup for provider-owned session resources and returns a function that unregisters it.
func RegisterTextModelSource ¶ added in v0.6.0
func RegisterTextModelSource(registry *Registry, provider ProviderID, source TextModelSource, opts ...RegisterOption) error
RegisterTextModelSource registers a runtime text model source on registry.
func ResolveAuthForRequest ¶ added in v0.6.0
func ResolveAuthForRequest(ctx context.Context, model Model, opts Options) (Options, Credential, error)
ResolveAuthForRequest resolves request auth and returns options augmented with descriptor-provided provider configuration. Caller-supplied headers and provider options keep precedence over auth-derived values.
func RetryAfter ¶
RetryAfter returns the duration requested by a Retry-After header.
func RetryableNetworkError ¶
RetryableNetworkError reports whether err represents a transient network failure that occurred before an HTTP response body was returned.
func RetryableStatusCode ¶
RetryableStatusCode reports whether status is safe for pre-body-consumption HTTP retries.
func RunEmbeddingPayloadDebugHooks ¶ added in v0.3.0
func RunEmbeddingPayloadDebugHooks(ctx context.Context, opts Options, provider ProviderID, api EmbeddingAPI, model ModelID, payload []byte, headers http.Header) error
RunEmbeddingPayloadDebugHooks runs embedding payload hooks with redacted copies.
func RunImagePayloadDebugHooks ¶
func RunImagePayloadDebugHooks(ctx context.Context, opts Options, provider ProviderID, api ImageAPI, model ModelID, payload []byte, headers http.Header) error
RunImagePayloadDebugHooks runs image payload hooks with redacted copies.
func RunTextPayloadDebugHooks ¶
func RunTextPayloadDebugHooks(ctx context.Context, opts Options, provider ProviderID, api API, model ModelID, payload []byte, headers http.Header) error
RunTextPayloadDebugHooks runs text payload hooks with redacted copies.
func ToolErrorMessage ¶
ToolErrorMessage converts a tool validation failure into text suitable for a ToolError result, so the model can retry with corrected arguments.
func ValidateModelRef ¶
ValidateModelRef validates the minimum fields needed to identify a model.
func ValidateRequest ¶
ValidateRequest checks that req is structurally safe to persist and replay.
func ValidateToolCall ¶
ValidateToolCall validates a model-emitted tool call against the matching tool's JSON Schema-compatible InputSchema. It returns a decoded copy of the arguments on success and never mutates the supplied tool schema or call arguments.
func ValidateToolCallWithOptions ¶ added in v0.6.0
func ValidateToolCallWithOptions(tools []Tool, call ToolCall, options ToolValidationOptions) (map[string]any, error)
ValidateToolCallWithOptions validates a model-emitted tool call against the matching tool's JSON Schema-compatible InputSchema. It returns a decoded copy of the arguments on success and never mutates the supplied tool schema or call arguments.
Types ¶
type API ¶
type API string
API identifies a chat or text generation provider API surface.
const ( // APIOpenAICompletions identifies the OpenAI chat completions API. APIOpenAICompletions API = "openai-completions" // APIOpenAIResponses identifies the OpenAI responses API. APIOpenAIResponses API = "openai-responses" // APIAzureOpenAIResponses identifies the Azure OpenAI responses API. APIAzureOpenAIResponses API = "azure-openai-responses" // APIOpenAICodexResponses identifies the OpenAI Codex responses API. APIOpenAICodexResponses API = "openai-codex-responses" // APIAnthropicMessages identifies the Anthropic messages API. APIAnthropicMessages API = "anthropic-messages" // APIBedrockConverseStream identifies the Amazon Bedrock converse stream API. APIBedrockConverseStream API = "bedrock-converse-stream" // APIGoogleGenerativeAI identifies the Google Generative AI API. APIGoogleGenerativeAI API = "google-generative-ai" // APIGoogleVertex identifies the Google Vertex AI API. APIGoogleVertex API = "google-vertex" // APIMistralConversations identifies the Mistral conversations API. APIMistralConversations API = "mistral-conversations" // APIRadiusMessages identifies the Radius gateway messages API. APIRadiusMessages API = "radius-messages" )
type APIKeyAuth ¶ added in v0.6.0
type APIKeyAuth struct {
Name string
EnvVars []string
Resolve APIKeyAuthResolver
}
APIKeyAuth describes stored API-key and environment fallback auth.
func EnvironmentAPIKeyAuth ¶ added in v0.6.0
func EnvironmentAPIKeyAuth(name string, envVars ...string) *APIKeyAuth
EnvironmentAPIKeyAuth constructs API-key auth that prefers a stored key and falls back to ordered environment variables.
type APIKeyAuthResolver ¶ added in v0.6.0
type APIKeyAuthResolver func(context.Context, Model, Options, StoredCredential, bool) (AuthResolution, bool, error)
APIKeyAuthResolver resolves API-key auth, optionally using a stored credential.
type AnthropicCompatSupport ¶ added in v0.2.0
type AnthropicCompatSupport string
AnthropicCompatSupport identifies whether an Anthropic Messages-compatible feature is known to be supported by a provider or endpoint.
const ( // AnthropicCompatDefault uses provider and endpoint defaults. AnthropicCompatDefault AnthropicCompatSupport = "" // AnthropicCompatSupported forces a compatibility feature on. AnthropicCompatSupported AnthropicCompatSupport = "supported" // AnthropicCompatUnsupported forces a compatibility feature off. AnthropicCompatUnsupported AnthropicCompatSupport = "unsupported" )
type AnthropicMessagesCompat ¶ added in v0.2.0
type AnthropicMessagesCompat struct {
SupportsEagerToolInputStreaming AnthropicCompatSupport `json:"supportsEagerToolInputStreaming,omitempty"`
SupportsLongCacheRetention AnthropicCompatSupport `json:"supportsLongCacheRetention,omitempty"`
SupportsSessionAffinity AnthropicCompatSupport `json:"supportsSessionAffinity,omitempty"`
SupportsCacheControlOnTools AnthropicCompatSupport `json:"supportsCacheControlOnTools,omitempty"`
SupportsEmptyThinkingSignature AnthropicCompatSupport `json:"supportsEmptyThinkingSignature,omitempty"`
SupportsTemperature AnthropicCompatSupport `json:"supportsTemperature,omitempty"`
SupportsDisabledThinking AnthropicCompatSupport `json:"supportsDisabledThinking,omitempty"`
SupportsToolReferences AnthropicCompatSupport `json:"supportsToolReferences,omitempty"`
ThinkingFormat AnthropicThinkingFormat `json:"thinkingFormat,omitempty"`
}
AnthropicMessagesCompat describes Messages compatibility differences for Anthropic-compatible routers and custom endpoints. Leave fields at their zero value to use provider or base-URL detection.
type AnthropicOptions ¶
type AnthropicOptions struct {
ThinkingBudgetTokens *int
ToolChoice *AnthropicToolChoice
ThinkingDisplay AnthropicThinkingDisplay
InterleavedThinking *bool
OutputFormat any
DisableParallelToolUse *bool
}
AnthropicOptions carries Anthropic-specific request options known to the root package without importing provider adapters.
type AnthropicThinkingDisplay ¶ added in v0.4.0
type AnthropicThinkingDisplay string
AnthropicThinkingDisplay controls how Claude thinking content is returned when the model supports the display field.
const ( // AnthropicThinkingDisplaySummarized requests summarized thinking text. AnthropicThinkingDisplaySummarized AnthropicThinkingDisplay = "summarized" // AnthropicThinkingDisplayOmitted asks Anthropic to omit thinking text while // preserving signatures for replay. AnthropicThinkingDisplayOmitted AnthropicThinkingDisplay = "omitted" )
type AnthropicThinkingFormat ¶ added in v0.2.0
type AnthropicThinkingFormat string
AnthropicThinkingFormat identifies how Anthropic Messages thinking is encoded by a provider or endpoint.
const ( // AnthropicThinkingDefault uses provider and endpoint defaults. AnthropicThinkingDefault AnthropicThinkingFormat = "" // AnthropicThinkingBudget sends budget-token thinking controls. AnthropicThinkingBudget AnthropicThinkingFormat = "budget" // AnthropicThinkingAdaptive sends adaptive thinking plus output_config effort. AnthropicThinkingAdaptive AnthropicThinkingFormat = "adaptive" )
type AnthropicToolChoice ¶ added in v0.4.0
type AnthropicToolChoice struct {
Type AnthropicToolChoiceType `json:"type"`
Name string `json:"name,omitempty"`
}
AnthropicToolChoice carries Anthropic Messages tool choice controls.
type AnthropicToolChoiceType ¶ added in v0.4.0
type AnthropicToolChoiceType string
AnthropicToolChoiceType identifies Anthropic Messages tool selection behavior.
const ( // AnthropicToolChoiceAuto lets Anthropic choose whether to call a tool. AnthropicToolChoiceAuto AnthropicToolChoiceType = "auto" // AnthropicToolChoiceAny requires Anthropic to call one of the supplied tools. AnthropicToolChoiceAny AnthropicToolChoiceType = "any" // AnthropicToolChoiceNone prevents Anthropic from calling tools. AnthropicToolChoiceNone AnthropicToolChoiceType = "none" // AnthropicToolChoiceTool requires Anthropic to call the named tool. AnthropicToolChoiceTool AnthropicToolChoiceType = "tool" )
type AssistantImages ¶
type AssistantImages struct {
Images []ImageInput `json:"images,omitempty"`
ResponseID string `json:"responseId,omitempty"`
StopReason StopReason `json:"stopReason,omitempty"`
Errors []ImageError `json:"errors,omitempty"`
Usage *Usage `json:"usage,omitempty"`
Cost *Cost `json:"cost,omitempty"`
Model ModelID `json:"model,omitempty"`
Provider ProviderID `json:"provider,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
AssistantImages is provider-neutral image output plus generation metadata.
func CollectImages ¶ added in v0.3.0
func CollectImages(ctx context.Context, stream *ImageStream) (AssistantImages, error)
CollectImages consumes stream until it receives a terminal event or ctx is canceled.
func GenerateImages ¶
func GenerateImages(ctx context.Context, model ImageModel, req ImageRequest, opts ...ImageOption) (AssistantImages, error)
GenerateImages calls the registered image provider using the default registry.
type AssistantMessage ¶
type AssistantMessage struct {
Content []ContentBlock `json:"content,omitempty"`
StopReason StopReason `json:"stopReason,omitempty"`
Usage *Usage `json:"usage,omitempty"`
Cost *Cost `json:"cost,omitempty"`
Model ModelID `json:"model,omitempty"`
Provider ProviderID `json:"provider,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
}
AssistantMessage is provider-neutral assistant output plus turn metadata.
func Collect ¶
func Collect(ctx context.Context, stream *Stream) (AssistantMessage, error)
Collect consumes stream until it receives a terminal event or ctx is canceled.
func Complete ¶
func Complete(ctx context.Context, model Model, req Request, opts ...Option) (AssistantMessage, error)
Complete collects a provider stream using the default registry.
func (AssistantMessage) Citations ¶ added in v0.6.0
func (m AssistantMessage) Citations() []ResultCitation
Citations returns normalized citations attached to all assistant content blocks, preserving content order.
func (AssistantMessage) ResponseID ¶ added in v0.6.0
func (m AssistantMessage) ResponseID() string
ResponseID returns the provider response identifier reported on the assistant message, when one is available.
func (AssistantMessage) ResponseModel ¶ added in v0.6.0
func (m AssistantMessage) ResponseModel() ModelID
ResponseModel returns the concrete provider-routed response model reported on the assistant message, when it differs from the requested model and is available.
func (AssistantMessage) Sources ¶ added in v0.6.0
func (m AssistantMessage) Sources() []ResultSource
Sources returns normalized source entries reported on the assistant message.
type AuthResolution ¶ added in v0.6.0
type AuthResolution struct {
Credential Credential
ProviderEnv map[string]string
BaseURL string
Headers map[string]string
ProviderOptions map[string]any
Source string
}
AuthResolution is provider auth resolved for one model request.
func ResolveAuthResolution ¶ added in v0.6.0
ResolveAuthResolution resolves request auth through opts.AuthResolver.
func ResolveProviderAuth ¶ added in v0.6.0
func ResolveProviderAuth(ctx context.Context, model Model, opts Options, auth ProviderAuth, store CredentialStore) (AuthResolution, bool, error)
ResolveProviderAuth resolves auth using a descriptor and optional store.
type AuthResolutionResolver ¶ added in v0.6.0
type AuthResolutionResolver interface {
ResolveAuthResolution(context.Context, Model, Options) (AuthResolution, error)
}
AuthResolutionResolver resolves provider credentials plus provider-scoped request configuration for a request.
type AuthResolver ¶
AuthResolver resolves provider credentials for a request.
type AuthResolverFunc ¶
AuthResolverFunc adapts a function into an AuthResolver.
func (AuthResolverFunc) Resolve ¶
func (f AuthResolverFunc) Resolve(ctx context.Context, model Model, opts Options) (Credential, error)
Resolve calls f.
type AzureOpenAIResponsesConfig ¶
type AzureOpenAIResponsesConfig struct {
Endpoint string `json:"endpoint,omitempty"`
Deployment string `json:"deployment,omitempty"`
APIVersion string `json:"apiVersion,omitempty"`
APIKeyEnvVar string `json:"apiKeyEnvVar,omitempty"`
CredentialSource string `json:"credentialSource,omitempty"`
}
AzureOpenAIResponsesConfig carries Azure-specific model metadata for the Responses API. Endpoint is the Azure OpenAI resource endpoint, Deployment is the deployment name sent as the Responses model, APIVersion is the api-version query parameter, APIKeyEnvVar optionally overrides the default AZURE_OPENAI_API_KEY lookup, and CredentialSource may be "api-key" or "token" when callers need to document the intended auth path.
type BedrockOptions ¶ added in v0.2.0
type BedrockOptions struct {
ToolChoice *BedrockToolChoice
BearerToken string
ThinkingDisplay BedrockThinkingDisplay
InterleavedThinking *bool
StopSequences []string
TopP *float64
ResponseFormat any
RequestMetadata map[string]string
AdditionalModelRequestFields map[string]any
AdditionalModelResponseFieldPaths []string
}
BedrockOptions carries Bedrock-specific request options known to the root package without importing the provider adapter.
type BedrockThinkingDisplay ¶ added in v0.2.0
type BedrockThinkingDisplay string
BedrockThinkingDisplay controls how Claude thinking content is returned by Bedrock when the model supports the display field.
const ( // BedrockThinkingDisplaySummarized requests summarized thinking text. BedrockThinkingDisplaySummarized BedrockThinkingDisplay = "summarized" // BedrockThinkingDisplayOmitted asks Bedrock to omit thinking text while // preserving signatures for replay. BedrockThinkingDisplayOmitted BedrockThinkingDisplay = "omitted" )
type BedrockToolChoice ¶ added in v0.2.0
type BedrockToolChoice struct {
Type BedrockToolChoiceType `json:"type"`
Name string `json:"name,omitempty"`
}
BedrockToolChoice carries Bedrock Converse tool choice controls.
type BedrockToolChoiceType ¶ added in v0.2.0
type BedrockToolChoiceType string
BedrockToolChoiceType identifies Bedrock Converse tool selection behavior.
const ( // BedrockToolChoiceAuto lets Bedrock choose whether to call a tool. BedrockToolChoiceAuto BedrockToolChoiceType = "auto" // BedrockToolChoiceAny requires Bedrock to call one of the supplied tools. BedrockToolChoiceAny BedrockToolChoiceType = "any" // BedrockToolChoiceNone omits tools from the Bedrock request. BedrockToolChoiceNone BedrockToolChoiceType = "none" // BedrockToolChoiceTool requires Bedrock to call the named tool. BedrockToolChoiceTool BedrockToolChoiceType = "tool" )
type CacheRetention ¶
type CacheRetention string
CacheRetention identifies how long provider-side prompt cache entries may live.
const ( // CacheRetentionNone disables provider-side prompt caching. CacheRetentionNone CacheRetention = "none" // CacheRetentionShort identifies provider cache entries kept briefly. CacheRetentionShort CacheRetention = "short" // CacheRetentionLong identifies provider cache entries kept beyond a single request. CacheRetentionLong CacheRetention = "long" // CacheRetentionEphemeral identifies provider cache entries kept briefly. CacheRetentionEphemeral CacheRetention = "ephemeral" // CacheRetentionPersistent identifies provider cache entries kept beyond a single request. CacheRetentionPersistent CacheRetention = "persistent" )
func (CacheRetention) CacheEnabled ¶
func (retention CacheRetention) CacheEnabled() bool
CacheEnabled reports whether this retention requests provider-side prompt caching. Empty retention and CacheRetentionNone both mean no cache.
func (CacheRetention) CacheLongLived ¶
func (retention CacheRetention) CacheLongLived() bool
CacheLongLived reports whether this retention asks for a long-lived prompt cache entry.
func (CacheRetention) CacheShortLived ¶
func (retention CacheRetention) CacheShortLived() bool
CacheShortLived reports whether this retention asks for a short-lived prompt cache entry.
type CachedTextModelSource ¶ added in v0.7.0
type CachedTextModelSource interface {
TextModelSource
CachedTextModels(context.Context) ([]Model, error)
}
CachedTextModelSource restores text models that a source previously stored outside the registry.
Cached models are applied through the same validation and source-ownership rules as refreshed models.
type ChainAuthResolver ¶
type ChainAuthResolver struct {
Client AuthResolver
Environment AuthResolver
ProviderCallbacks map[ProviderID]AuthResolver
DefaultProviderCallbacks map[ProviderID]AuthResolver
}
ChainAuthResolver resolves credentials through sigma's standard precedence.
ProviderCallbacks holds request-scoped provider callbacks and takes precedence over the client resolver. DefaultProviderCallbacks holds callbacks installed as client or model defaults; they resolve after the client resolver and environment, preserving their pre-request-scoped position so an explicit client resolver keeps winning over ambient defaults.
func (ChainAuthResolver) Resolve ¶
func (r ChainAuthResolver) Resolve(ctx context.Context, model Model, opts Options) (Credential, error)
Resolve checks request overrides, request-scoped provider callbacks, the client resolver, environment, then default provider callbacks.
func (ChainAuthResolver) ResolveAuthResolution ¶ added in v0.6.0
func (r ChainAuthResolver) ResolveAuthResolution(ctx context.Context, model Model, opts Options) (AuthResolution, error)
ResolveAuthResolution checks request overrides, request-scoped provider callbacks, the client resolver, environment, then default provider callbacks.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client coordinates model lookup and generation requests.
func (*Client) Complete ¶
func (c *Client) Complete(ctx context.Context, model Model, req Request, opts ...Option) (AssistantMessage, error)
Complete collects a provider stream into a final assistant message.
func (*Client) CompleteText ¶
func (c *Client) CompleteText(ctx context.Context, model Model, prompt string, opts ...Option) (string, error)
CompleteText is a text-only helper for simple prompt/response workflows.
It returns an error if the final assistant message contains non-text content, so tool calls and thinking blocks are not silently discarded.
func (*Client) Embed ¶ added in v0.3.0
func (c *Client) Embed(ctx context.Context, model EmbeddingModel, req EmbeddingRequest, opts ...EmbeddingOption) (Embeddings, error)
Embed calls the registered embedding provider for model.
func (*Client) EmbedBatch ¶ added in v0.3.0
func (c *Client) EmbedBatch(ctx context.Context, model EmbeddingModel, req EmbeddingRequest, config EmbeddingBatchConfig, opts ...EmbeddingOption) (EmbeddingBatchResult, error)
EmbedBatch embeds req.Inputs with duplicate reuse and retry-aware batch splitting.
func (*Client) EmbeddingModels ¶ added in v0.3.0
func (c *Client) EmbeddingModels() []EmbeddingModel
EmbeddingModels returns embedding models from the client registry.
func (*Client) GenerateImages ¶
func (c *Client) GenerateImages(ctx context.Context, model ImageModel, req ImageRequest, opts ...ImageOption) (AssistantImages, error)
GenerateImages calls the registered image provider for model.
func (*Client) GetEmbeddingModel ¶ added in v0.3.0
func (c *Client) GetEmbeddingModel(provider ProviderID, id ModelID) (EmbeddingModel, bool)
GetEmbeddingModel returns an embedding model by provider and model id.
func (*Client) GetImageModel ¶
func (c *Client) GetImageModel(provider ProviderID, id ModelID) (ImageModel, bool)
GetImageModel returns an image model by provider and model id.
func (*Client) GetModel ¶
func (c *Client) GetModel(provider ProviderID, id ModelID) (Model, bool)
GetModel returns a text model by provider and model id.
func (*Client) ImageModels ¶
func (c *Client) ImageModels() []ImageModel
ImageModels returns image models from the client registry.
func (*Client) Models ¶
func (c *Client) Models(filters ...ModelFilter) []Model
Models returns text models matching all filters.
func (*Client) RefreshEmbeddingModels ¶ added in v0.6.0
func (c *Client) RefreshEmbeddingModels(ctx context.Context, providers ...ProviderID) error
RefreshEmbeddingModels refreshes runtime embedding model sources on the client's registry.
func (*Client) RefreshImageModels ¶ added in v0.6.0
func (c *Client) RefreshImageModels(ctx context.Context, providers ...ProviderID) error
RefreshImageModels refreshes runtime image model sources on the client's registry.
func (*Client) RefreshTextModels ¶ added in v0.6.0
func (c *Client) RefreshTextModels(ctx context.Context, providers ...ProviderID) error
RefreshTextModels refreshes runtime text model sources on the client's registry.
func (*Client) RestoreTextModels ¶ added in v0.7.0
func (c *Client) RestoreTextModels(ctx context.Context, providers ...ProviderID) error
RestoreTextModels restores cached runtime text models on the client's registry.
func (*Client) StreamImages ¶ added in v0.3.0
func (c *Client) StreamImages(ctx context.Context, model ImageModel, req ImageRequest, opts ...ImageOption) *ImageStream
StreamImages starts a streaming image provider call for model.
type ClientEmbeddingEmbedder ¶ added in v0.3.0
type ClientEmbeddingEmbedder struct {
// contains filtered or unexported fields
}
ClientEmbeddingEmbedder adapts a Client and EmbeddingModel to the EmbeddingEmbedder interface.
func NewEmbeddingEmbedder ¶ added in v0.3.0
func NewEmbeddingEmbedder(client *Client, model EmbeddingModel, config EmbeddingEmbedderConfig, opts ...EmbeddingOption) *ClientEmbeddingEmbedder
NewEmbeddingEmbedder wraps client and model with query/document embedding helpers.
func (*ClientEmbeddingEmbedder) EmbedDocuments ¶ added in v0.3.0
func (e *ClientEmbeddingEmbedder) EmbedDocuments(ctx context.Context, texts []string) ([][]float32, error)
EmbedDocuments embeds texts as document inputs.
func (*ClientEmbeddingEmbedder) EmbedQuery ¶ added in v0.3.0
EmbedQuery embeds text as a query input and returns its vector.
type ClientOption ¶
type ClientOption func(*Client)
ClientOption configures a Client.
func WithAuthResolver ¶
func WithAuthResolver(resolver AuthResolver) ClientOption
WithAuthResolver configures the credential resolver exposed to providers.
func WithCredentialStore ¶ added in v0.6.0
func WithCredentialStore(store CredentialStore) ClientOption
WithCredentialStore configures stored credentials for opt-in provider auth.
The store is inert unless WithStoredProviderAuth is also configured.
func WithDefaultHeader ¶
func WithDefaultHeader(key, value string) ClientOption
WithDefaultHeader configures a default request header.
func WithDefaultHeaders ¶
func WithDefaultHeaders(headers map[string]string) ClientOption
WithDefaultHeaders configures default request headers.
func WithDefaultOptions ¶
func WithDefaultOptions(opts ...Option) ClientOption
WithDefaultOptions configures default provider request options.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient configures the HTTP client exposed to providers.
func WithRegistry ¶
func WithRegistry(registry *Registry) ClientOption
WithRegistry configures the client to use a registry.
func WithStoredProviderAuth ¶ added in v0.6.0
func WithStoredProviderAuth() ClientOption
WithStoredProviderAuth enables store-backed provider auth resolution.
type CloudCredentialProvider ¶
type CloudCredentialProvider interface {
Credential(context.Context, Model, Options) (Credential, error)
}
CloudCredentialProvider provides cloud credential material for a provider adapter.
type ContentBlock ¶
type ContentBlock struct {
Type ContentBlockType `json:"type"`
Text string `json:"text,omitempty"`
ThinkingText string `json:"thinking,omitempty"`
Signature string `json:"signature,omitempty"`
Redacted bool `json:"redacted,omitempty"`
MIMEType string `json:"mimeType,omitempty"`
ImageSource string `json:"imageSource,omitempty"`
DocumentSource string `json:"documentSource,omitempty"`
Filename string `json:"filename,omitempty"`
FileID string `json:"fileID,omitempty"`
Data string `json:"data,omitempty"`
URL string `json:"url,omitempty"`
ToolCallID string `json:"toolCallID,omitempty"`
ToolName string `json:"toolName,omitempty"`
ToolArguments any `json:"toolArguments,omitempty"`
ProviderSignature string `json:"providerSignature,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
ExtraFields map[string]any `json:"-"`
}
ContentBlock is a discriminated unit of message content.
Text blocks use Text. Thinking blocks use ThinkingText plus optional Signature, Redacted, and ProviderSignature. Image blocks use MIMEType, ImageSource, Data, and URL. Document blocks use MIMEType, DocumentSource, Filename, Data, URL, and FileID. Tool-call blocks use ToolCallID, ToolName, and ToolArguments. ProviderMetadata carries opaque provider fields for later replay without requiring provider-specific conversion in this package.
func DocumentBase64 ¶ added in v0.6.0
func DocumentBase64(mimeType string, filename string, data string) ContentBlock
DocumentBase64 constructs a document content block backed by base64 data.
func DocumentFileID ¶ added in v0.6.0
func DocumentFileID(mimeType string, filename string, fileID string) ContentBlock
DocumentFileID constructs a document content block backed by a provider file ID.
func DocumentURL ¶ added in v0.6.0
func DocumentURL(mimeType string, filename string, url string) ContentBlock
DocumentURL constructs a document content block backed by a URL.
func ImageBase64 ¶
func ImageBase64(mimeType string, data string) ContentBlock
ImageBase64 constructs an image content block backed by base64 data.
func ImageURL ¶
func ImageURL(mimeType string, url string) ContentBlock
ImageURL constructs an image content block backed by a URL.
func Thinking ¶
func Thinking(text string, signature string) ContentBlock
Thinking constructs a thinking content block.
func ToolCallBlock ¶
func ToolCallBlock(id string, name string, arguments any) ContentBlock
ToolCallBlock constructs an assistant tool-call content block.
func (ContentBlock) Citations ¶ added in v0.6.0
func (b ContentBlock) Citations() []ResultCitation
Citations returns normalized citations attached to this content block.
func (ContentBlock) Clone ¶ added in v0.6.0
func (b ContentBlock) Clone() ContentBlock
Clone returns a deep copy of the block: mutating the copy's tool arguments, provider metadata, or extra fields does not affect the original. New reference-typed fields added to ContentBlock must be cloned here so every package copying blocks picks up the change.
func (ContentBlock) MarshalJSON ¶ added in v0.6.0
func (b ContentBlock) MarshalJSON() ([]byte, error)
func (*ContentBlock) UnmarshalJSON ¶ added in v0.6.0
func (b *ContentBlock) UnmarshalJSON(data []byte) error
type ContentBlockType ¶
type ContentBlockType string
ContentBlockType identifies the shape of a message content block.
const ( // ContentBlockText identifies a text content block. ContentBlockText ContentBlockType = "text" // ContentBlockThinking identifies a thinking content block. ContentBlockThinking ContentBlockType = "thinking" // ContentBlockImage identifies an image content block. ContentBlockImage ContentBlockType = "image" // ContentBlockDocument identifies a document content block. ContentBlockDocument ContentBlockType = "document" // ContentBlockToolCall identifies a tool-call content block. ContentBlockToolCall ContentBlockType = "tool-call" )
type Cost ¶
type Cost struct {
InputCost float64 `json:"inputCost,omitempty"`
OutputCost float64 `json:"outputCost,omitempty"`
CacheReadInputCost float64 `json:"cacheReadInputCost,omitempty"`
CacheWriteInputCost float64 `json:"cacheWriteInputCost,omitempty"`
TotalCost float64 `json:"totalCost,omitempty"`
Currency string `json:"currency,omitempty"`
ProviderReportedCost *float64 `json:"providerReportedCost,omitempty"`
ProviderReportedCurrency string `json:"providerReportedCurrency,omitempty"`
}
Cost records estimated and provider-reported cost accounting for a model turn.
The component costs and TotalCost are Sigma estimates calculated from model pricing metadata. ProviderReportedCost is only populated when the provider returns an explicit numeric cost.
func CostForEmbeddingUsage ¶ added in v0.3.0
func CostForEmbeddingUsage(model EmbeddingModel, usage Usage) Cost
CostForEmbeddingUsage calculates deterministic embedding request cost from model rates.
func CostForUsage ¶
CostForUsage calculates deterministic per-turn cost from model rates.
Model cost rates are expressed as currency units per one million tokens. CostCurrency records the rate currency; when empty, USD is assumed. The helper does not round so callers can choose their own display precision.
type Credential ¶
type Credential struct {
Type CredentialType
Value string
Expiry time.Time
Source string
Metadata map[string]any
}
Credential carries authentication material for a provider.
func (Credential) Format ¶
func (c Credential) Format(state fmt.State, verb rune)
Format prevents fmt from printing Credential.Value with struct formatting verbs.
func (Credential) String ¶
func (c Credential) String() string
String returns a diagnostic-safe credential description.
type CredentialModifyFunc ¶ added in v0.6.0
type CredentialModifyFunc func(current StoredCredential, ok bool) (next StoredCredential, nextOK bool, err error)
CredentialModifyFunc receives the current stored credential. Return ok=false to leave the existing credential unchanged.
type CredentialStore ¶ added in v0.6.0
type CredentialStore interface {
ReadCredential(context.Context, ProviderID) (StoredCredential, bool, error)
ModifyCredential(context.Context, ProviderID, CredentialModifyFunc) (StoredCredential, bool, error)
DeleteCredential(context.Context, ProviderID) error
}
CredentialStore stores one credential per provider.
type CredentialType ¶
type CredentialType string
CredentialType identifies the kind of authentication material.
const ( // CredentialTypeAPIKey identifies a static API key. CredentialTypeAPIKey CredentialType = "api-key" // CredentialTypeOAuthToken identifies a bearer token from an OAuth provider. CredentialTypeOAuthToken CredentialType = "oauth-token" // CredentialTypeCloudCredential identifies cloud provider credential material. CredentialTypeCloudCredential CredentialType = "cloud-credential" )
type CredentialUnavailableError ¶
type CredentialUnavailableError struct {
}
CredentialUnavailableError reports a failed credential lookup without secrets.
func (*CredentialUnavailableError) Error ¶
func (e *CredentialUnavailableError) Error() string
Error returns diagnostic-safe source information.
func (*CredentialUnavailableError) Is ¶
func (e *CredentialUnavailableError) Is(target error) bool
Is supports errors.Is(err, ErrCredentialUnavailable).
type Diagnostic ¶
type Diagnostic struct {
Kind string `json:"kind,omitempty"`
Message string `json:"message,omitempty"`
Provider ProviderID `json:"provider,omitempty"`
API API `json:"api,omitempty"`
Model ModelID `json:"model,omitempty"`
StatusCode int `json:"statusCode,omitempty"`
RequestID string `json:"requestID,omitempty"`
ProviderCode string `json:"providerCode,omitempty"`
ProviderMessage string `json:"providerMessage,omitempty"`
RetryAfterMillis int64 `json:"retryAfterMillis,omitempty"`
MaxRetryDelayMillis int64 `json:"maxRetryDelayMillis,omitempty"`
BodyPreview string `json:"bodyPreview,omitempty"`
UnderlyingMessage string `json:"underlyingMessage,omitempty"`
}
Diagnostic is safe-to-log provider/runtime context that may be attached to an AssistantMessage. It must contain metadata and redacted previews only, never raw request or response payloads.
type EmbeddingAPI ¶ added in v0.3.0
type EmbeddingAPI string
EmbeddingAPI identifies a vector embedding provider API surface.
const ( // EmbeddingAPIOpenAIEmbeddings identifies OpenAI's embeddings API. EmbeddingAPIOpenAIEmbeddings EmbeddingAPI = "openai-embeddings" // EmbeddingAPIGoogleEmbeddings identifies Google's Gemini embeddings API. EmbeddingAPIGoogleEmbeddings EmbeddingAPI = "google-embeddings" // EmbeddingAPIGoogleVertexEmbeddings identifies Google's Vertex AI embeddings API. EmbeddingAPIGoogleVertexEmbeddings EmbeddingAPI = "google-vertex-embeddings" // EmbeddingAPIBedrockEmbeddings identifies Amazon Bedrock's InvokeModel embeddings API. EmbeddingAPIBedrockEmbeddings EmbeddingAPI = "bedrock-embeddings" )
type EmbeddingAttempt ¶ added in v0.3.0
type EmbeddingAttempt struct {
Provider ProviderID `json:"provider,omitempty"`
API EmbeddingAPI `json:"api,omitempty"`
Model ModelID `json:"model,omitempty"`
Attempt int `json:"attempt,omitempty"`
StatusCode int `json:"statusCode,omitempty"`
RequestID string `json:"requestID,omitempty"`
Latency time.Duration `json:"latency,omitempty"`
}
EmbeddingAttempt records SDK-level metadata for one embedding provider attempt.
type EmbeddingBatchConfig ¶ added in v0.3.0
type EmbeddingBatchConfig struct {
ReuseDuplicateInputs bool
MaxRetries int
MaxParallelBatches int
MaxBatchInputs int
MaxBatchBytes int
SplitOversized bool
Cache EmbeddingCache
SplitPolicy EmbeddingSplitPolicy
// Progress receives batch progress callbacks. When MaxParallelBatches is
// greater than zero it may be called concurrently from multiple goroutines,
// so it must be safe for concurrent use.
Progress func(EmbeddingBatchProgress) error
}
EmbeddingBatchConfig configures resilient embedding batch behaviour.
type EmbeddingBatchPhase ¶ added in v0.3.0
type EmbeddingBatchPhase string
EmbeddingBatchPhase identifies a resilient embedding batch progress stage.
const ( EmbeddingBatchPhaseCacheHit EmbeddingBatchPhase = "cache_hit" EmbeddingBatchPhaseCacheLookup EmbeddingBatchPhase = "cache_lookup" EmbeddingBatchPhaseCacheStore EmbeddingBatchPhase = "cache_store" EmbeddingBatchPhaseBatchStart EmbeddingBatchPhase = "batch_start" EmbeddingBatchPhaseBatchSuccess EmbeddingBatchPhase = "batch_success" EmbeddingBatchPhaseBatchError EmbeddingBatchPhase = "batch_error" EmbeddingBatchPhaseLimitSplit EmbeddingBatchPhase = "limit_split" EmbeddingBatchPhaseSplit EmbeddingBatchPhase = "split" )
type EmbeddingBatchProgress ¶ added in v0.3.0
type EmbeddingBatchProgress struct {
Phase EmbeddingBatchPhase
Attempt int
BatchSize int
InputIndexes []int
SplitPart int
SplitTotal int
Err error
}
EmbeddingBatchProgress reports progress from EmbedBatch.
type EmbeddingBatchResult ¶ added in v0.3.0
type EmbeddingBatchResult struct {
Embeddings Embeddings
Reused []bool
Summary EmbeddingBatchSummary
}
EmbeddingBatchResult is ordered embedding output plus batch metadata.
func EmbedBatch ¶ added in v0.3.0
func EmbedBatch(ctx context.Context, model EmbeddingModel, req EmbeddingRequest, config EmbeddingBatchConfig, opts ...EmbeddingOption) (EmbeddingBatchResult, error)
EmbedBatch embeds req.Inputs using the default registry.
type EmbeddingBatchSummary ¶ added in v0.3.0
type EmbeddingBatchSummary struct {
RequestCount int
TotalRequestCount int
ErrorCount int
VectorCount int
StatusBuckets map[int]int
RequestIDs []string
Attempts []EmbeddingAttempt
Trace []EmbeddingBatchTraceEvent
Usage *Usage
Cost *Cost
}
EmbeddingBatchSummary reports aggregate provider work from EmbedBatch.
type EmbeddingBatchTraceEvent ¶ added in v0.3.0
type EmbeddingBatchTraceEvent struct {
Phase EmbeddingBatchPhase
Attempt int
BatchSize int
BatchBytes int
InputIndexes []int
MaxBatchInputs int
MaxBatchBytes int
CacheKey EmbeddingCacheKey
CacheHit bool
SplitPart int
SplitTotal int
SplitReason string
ErrorClass ErrorClass
ErrorMessage string
StatusCode int
ProviderCode string
RequestID string
Retryable bool
SplitRecoverable bool
ProviderAttempts []EmbeddingAttempt
}
EmbeddingBatchTraceEvent reports structured, redacted EmbedBatch execution metadata. It never includes raw input text.
type EmbeddingCache ¶ added in v0.3.0
type EmbeddingCache interface {
Get(EmbeddingCacheKey) (Embedding, bool, error)
Set(EmbeddingCacheKey, Embedding) error
}
EmbeddingCache stores embeddings for reuse across EmbedBatch calls.
When EmbeddingBatchConfig.MaxParallelBatches is greater than zero, Get and Set may be called concurrently from multiple goroutines, so implementations must be safe for concurrent use.
type EmbeddingCacheKey ¶ added in v0.3.0
type EmbeddingCacheKey struct {
Provider ProviderID
API EmbeddingAPI
Model ModelID
Dimensions int
InputType EmbeddingInputType
InputSHA256 string
}
EmbeddingCacheKey identifies one cacheable embedding input without exposing the raw input text.
type EmbeddingEmbedder ¶ added in v0.3.0
type EmbeddingEmbedder interface {
EmbedDocuments(ctx context.Context, texts []string) ([][]float32, error)
EmbedQuery(ctx context.Context, text string) ([]float32, error)
}
EmbeddingEmbedder creates query and document vectors through Sigma's provider-neutral embedding surface.
type EmbeddingEmbedderConfig ¶ added in v0.3.0
type EmbeddingEmbedderConfig struct {
Dimensions int
Batch EmbeddingBatchConfig
}
EmbeddingEmbedderConfig configures NewEmbeddingEmbedder.
type EmbeddingInputType ¶ added in v0.3.0
type EmbeddingInputType string
EmbeddingInputType identifies the intended use for embedding inputs.
const ( // EmbeddingInputTypeQuery marks an embedding request as search-query input. EmbeddingInputTypeQuery EmbeddingInputType = "query" // EmbeddingInputTypeDocument marks an embedding request as document input. EmbeddingInputTypeDocument EmbeddingInputType = "document" )
type EmbeddingModel ¶ added in v0.3.0
type EmbeddingModel struct {
ID ModelID `json:"id"`
Provider ProviderID `json:"provider"`
API EmbeddingAPI `json:"api,omitempty"`
Name string `json:"name,omitempty"`
DefaultDimensions int `json:"defaultDimensions,omitempty"`
MinDimensions int `json:"minDimensions,omitempty"`
MaxDimensions int `json:"maxDimensions,omitempty"`
MaxInputTokens int `json:"maxInputTokens,omitempty"`
MaxBatchInputs int `json:"maxBatchInputs,omitempty"`
MaxBatchBytes int `json:"maxBatchBytes,omitempty"`
InputCostPerMillion float64 `json:"inputCostPerMillion,omitempty"`
CostCurrency string `json:"costCurrency,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
EmbeddingModel describes a provider embedding model available through sigma.
func EmbeddingModels ¶ added in v0.3.0
func EmbeddingModels() []EmbeddingModel
EmbeddingModels returns embedding models from the default registry.
func GetEmbeddingModel ¶ added in v0.3.0
func GetEmbeddingModel(provider ProviderID, id ModelID) (EmbeddingModel, bool)
GetEmbeddingModel returns an embedding model from the default registry.
func OpenAICompatibleEmbeddingModel ¶ added in v0.3.0
func OpenAICompatibleEmbeddingModel(config OpenAICompatibleEmbeddingModelConfig) EmbeddingModel
OpenAICompatibleEmbeddingModel constructs metadata for an OpenAI Embeddings-compatible model. Register the returned model on the same registry as an OpenAI embeddings provider, then pass that registry to NewClient with WithRegistry for an isolated setup.
type EmbeddingModelSource ¶ added in v0.6.0
type EmbeddingModelSource interface {
EmbeddingModels(context.Context) ([]EmbeddingModel, error)
}
EmbeddingModelSource lists embedding models for a provider-owned runtime source.
type EmbeddingModelSourceFunc ¶ added in v0.6.0
type EmbeddingModelSourceFunc func(context.Context) ([]EmbeddingModel, error)
EmbeddingModelSourceFunc adapts a function into an EmbeddingModelSource.
func (EmbeddingModelSourceFunc) EmbeddingModels ¶ added in v0.6.0
func (f EmbeddingModelSourceFunc) EmbeddingModels(ctx context.Context) ([]EmbeddingModel, error)
EmbeddingModels calls f.
type EmbeddingOption ¶ added in v0.3.0
type EmbeddingOption func(*Options)
EmbeddingOption configures a single embedding provider request.
func WithEmbeddingAPIKey ¶ added in v0.3.0
func WithEmbeddingAPIKey(apiKey string) EmbeddingOption
WithEmbeddingAPIKey configures a request-scoped embedding API key override.
func WithEmbeddingAuthResolver ¶ added in v0.3.0
func WithEmbeddingAuthResolver(resolver AuthResolver) EmbeddingOption
WithEmbeddingAuthResolver configures a request-scoped credential resolver.
func WithEmbeddingHTTPClient ¶ added in v0.3.0
func WithEmbeddingHTTPClient(httpClient *http.Client) EmbeddingOption
WithEmbeddingHTTPClient configures the HTTP client exposed to embedding providers.
func WithEmbeddingHeader ¶ added in v0.3.0
func WithEmbeddingHeader(key, value string) EmbeddingOption
WithEmbeddingHeader adds or replaces an embedding request header.
func WithEmbeddingHeaders ¶ added in v0.3.0
func WithEmbeddingHeaders(headers map[string]string) EmbeddingOption
WithEmbeddingHeaders adds or replaces embedding request headers.
func WithEmbeddingMaxRetries ¶ added in v0.3.0
func WithEmbeddingMaxRetries(maxRetries int) EmbeddingOption
WithEmbeddingMaxRetries configures the maximum embedding provider retry attempts.
func WithEmbeddingMaxRetryDelay ¶ added in v0.3.0
func WithEmbeddingMaxRetryDelay(maxRetryDelay time.Duration) EmbeddingOption
WithEmbeddingMaxRetryDelay configures the maximum delay between embedding provider retries.
func WithEmbeddingMetadata ¶ added in v0.3.0
func WithEmbeddingMetadata(metadata map[string]any) EmbeddingOption
WithEmbeddingMetadata adds or replaces provider-neutral embedding request metadata.
func WithEmbeddingMetadataValue ¶ added in v0.3.0
func WithEmbeddingMetadataValue(key string, value any) EmbeddingOption
WithEmbeddingMetadataValue adds or replaces one provider-neutral embedding metadata value.
func WithEmbeddingPayloadDebugHook ¶ added in v0.3.0
func WithEmbeddingPayloadDebugHook(hook EmbeddingPayloadDebugHook) EmbeddingOption
WithEmbeddingPayloadDebugHook adds a safe embedding request payload debug hook.
func WithEmbeddingProviderAuthResolver ¶ added in v0.3.0
func WithEmbeddingProviderAuthResolver(provider ProviderID, resolver AuthResolver) EmbeddingOption
WithEmbeddingProviderAuthResolver configures a provider-specific embedding credential callback.
func WithEmbeddingProviderOption ¶ added in v0.3.0
func WithEmbeddingProviderOption(provider ProviderID, key string, value any) EmbeddingOption
WithEmbeddingProviderOption adds or replaces one advanced provider-specific embedding value.
func WithEmbeddingProviderOptions ¶ added in v0.3.0
func WithEmbeddingProviderOptions(provider ProviderID, values map[string]any) EmbeddingOption
WithEmbeddingProviderOptions adds or replaces advanced provider-specific embedding values.
func WithEmbeddingResponseDebugHook ¶ added in v0.3.0
func WithEmbeddingResponseDebugHook(hook EmbeddingResponseDebugHook) EmbeddingOption
WithEmbeddingResponseDebugHook adds a safe embedding response debug hook.
func WithEmbeddingSuppressedHeader ¶ added in v0.6.0
func WithEmbeddingSuppressedHeader(key string) EmbeddingOption
WithEmbeddingSuppressedHeader removes a final outgoing embedding request header.
func WithEmbeddingSuppressedHeaders ¶ added in v0.6.0
func WithEmbeddingSuppressedHeaders(keys ...string) EmbeddingOption
WithEmbeddingSuppressedHeaders removes final outgoing embedding request headers.
func WithEmbeddingTimeout ¶ added in v0.3.0
func WithEmbeddingTimeout(timeout time.Duration) EmbeddingOption
WithEmbeddingTimeout configures the per-request embedding provider timeout.
type EmbeddingPayloadDebug ¶ added in v0.3.0
type EmbeddingPayloadDebug struct {
Provider ProviderID
API EmbeddingAPI
Model ModelID
Headers http.Header
Payload []byte
PayloadPreview string
}
EmbeddingPayloadDebug is the diagnostic view passed to embedding payload hooks.
type EmbeddingPayloadDebugHook ¶ added in v0.3.0
type EmbeddingPayloadDebugHook func(context.Context, EmbeddingPayloadDebug) error
EmbeddingPayloadDebugHook inspects a redacted copy of an embedding provider payload.
Hooks run after provider payload and headers are built and before the HTTP request is sent. Payload replacement is intentionally unsupported: Payload is a redacted copy for diagnostics, so mutating it cannot change the request body or corrupt a later retry attempt.
type EmbeddingProvider ¶ added in v0.3.0
type EmbeddingProvider interface {
API() EmbeddingAPI
Embed(context.Context, EmbeddingModel, EmbeddingRequest, Options) (Embeddings, error)
}
EmbeddingProvider adapts a provider API into sigma's vector embeddings interface.
type EmbeddingRequest ¶ added in v0.3.0
type EmbeddingRequest struct {
Inputs []string `json:"inputs,omitempty"`
Dimensions int `json:"dimensions,omitempty"`
InputType EmbeddingInputType `json:"inputType,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
EmbeddingRequest is the provider-neutral input for vector embeddings.
func EmbeddingDocuments ¶ added in v0.3.0
func EmbeddingDocuments(texts []string) EmbeddingRequest
EmbeddingDocuments builds an embedding request for document inputs.
func EmbeddingQuery ¶ added in v0.3.0
func EmbeddingQuery(text string) EmbeddingRequest
EmbeddingQuery builds an embedding request for one search-query input.
type EmbeddingResponseDebug ¶ added in v0.3.0
type EmbeddingResponseDebug struct {
Provider ProviderID
API EmbeddingAPI
Model ModelID
StatusCode int
Headers http.Header
RequestID string
}
EmbeddingResponseDebug is the diagnostic view passed to embedding response hooks.
type EmbeddingResponseDebugHook ¶ added in v0.3.0
type EmbeddingResponseDebugHook func(context.Context, EmbeddingResponseDebug) error
EmbeddingResponseDebugHook inspects redacted embedding response metadata before the response body is consumed.
type EmbeddingScore ¶ added in v0.3.0
EmbeddingScore is a candidate embedding plus its similarity score.
func RankEmbeddingsByCosine ¶ added in v0.3.0
func RankEmbeddingsByCosine(query []float32, candidates []Embedding) ([]EmbeddingScore, error)
RankEmbeddingsByCosine scores candidates against query and sorts by descending similarity.
type EmbeddingSplitPolicy ¶ added in v0.3.0
EmbeddingSplitPolicy configures oversized embedding input splitting.
type Embeddings ¶ added in v0.3.0
type Embeddings struct {
Vectors []Embedding `json:"vectors,omitempty"`
Usage *Usage `json:"usage,omitempty"`
Cost *Cost `json:"cost,omitempty"`
Model ModelID `json:"model,omitempty"`
Provider ProviderID `json:"provider,omitempty"`
Attempts []EmbeddingAttempt `json:"attempts,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
Embeddings is provider-neutral embedding output plus request metadata.
func Embed ¶ added in v0.3.0
func Embed(ctx context.Context, model EmbeddingModel, req EmbeddingRequest, opts ...EmbeddingOption) (Embeddings, error)
Embed calls the registered embedding provider using the default registry.
type EnvironmentAuthResolver ¶
EnvironmentAuthResolver resolves static API keys from environment variables.
func (EnvironmentAuthResolver) ConfiguredEnvVars ¶ added in v0.6.0
func (r EnvironmentAuthResolver) ConfiguredEnvVars(model Model) []string
ConfiguredEnvVars returns the ordered environment variable names that are currently set to non-empty values for model credentials. Secret values are not returned.
func (EnvironmentAuthResolver) EnvVars ¶ added in v0.6.0
func (r EnvironmentAuthResolver) EnvVars(model Model) []string
EnvVars returns the ordered environment variable names that would be checked for model credentials. Model metadata takes precedence over provider defaults. Secret values are not returned.
func (EnvironmentAuthResolver) Resolve ¶
func (r EnvironmentAuthResolver) Resolve(_ context.Context, model Model, _ Options) (Credential, error)
Resolve returns the first non-empty provider API key found in the environment.
type Error ¶
type Error struct {
Code ErrorCode
Message string
Provider ProviderID
Model ModelID
Err error
}
Error is the package error type.
type ErrorClass ¶ added in v0.3.0
type ErrorClass string
ErrorClass is a stable provider/model execution error category.
const ( ErrorClassUnknown ErrorClass = "unknown" ErrorClassTransient ErrorClass = "transient" ErrorClassRateLimited ErrorClass = "rate-limited" ErrorClassAuth ErrorClass = "auth" ErrorClassQuota ErrorClass = "quota" ErrorClassBilling ErrorClass = "billing" ErrorClassContextOverflow ErrorClass = "context-overflow" ErrorClassInvalidRequest ErrorClass = "invalid-request" ErrorClassProvider ErrorClass = "provider" )
type ErrorClassification ¶ added in v0.3.0
type ErrorClassification struct {
Class ErrorClass
Provider ProviderID
API API
Model ModelID
StatusCode int
ProviderCode string
Message string
RequestID string
RetryHint RetryHint
// SplitRecoverable reports whether a smaller request may recover from the
// same error even though retrying the identical request is not useful.
SplitRecoverable bool
Err error
}
ErrorClassification exposes provider-neutral handling hints for an error.
func ClassifyError ¶ added in v0.3.0
func ClassifyError(err error) ErrorClassification
ClassifyError returns stable provider-neutral classification for err.
type ErrorCode ¶
type ErrorCode string
ErrorCode identifies a sigma error category.
const ( // ErrorUnsupported indicates a requested capability is not implemented. ErrorUnsupported ErrorCode = "unsupported" // ErrorProviderNotFound indicates no provider is registered for a model. ErrorProviderNotFound ErrorCode = "provider-not-found" // ErrorModelNotFound indicates no model metadata is registered for a model. ErrorModelNotFound ErrorCode = "model-not-found" // ErrorContextOverflow indicates the provider rejected an oversized context. ErrorContextOverflow ErrorCode = "context-overflow" // ErrorToolValidation indicates local tool schema or call validation failed. ErrorToolValidation ErrorCode = "tool-validation" // ErrorProviderResponse indicates a provider returned a failed response. ErrorProviderResponse ErrorCode = "provider-response" )
const ( // ErrorStream indicates a provider stream ended with an error event. ErrorStream ErrorCode = "stream" // ErrorAborted indicates a stream ended because its context was canceled. ErrorAborted ErrorCode = "aborted" // ErrorStreamClosed indicates a write was attempted after stream closure. ErrorStreamClosed ErrorCode = "stream-closed" // ErrorInvalidStreamEvent indicates a writer was asked to emit an invalid event. ErrorInvalidStreamEvent ErrorCode = "invalid-stream-event" )
const ( // ErrorDebugHook indicates a caller-provided debug hook failed. ErrorDebugHook ErrorCode = "debug-hook" )
const ( // ErrorInvalidOptions indicates request options failed local validation. ErrorInvalidOptions ErrorCode = "invalid-options" )
const ( // ErrorInvalidRequest indicates a persisted request cannot be replayed safely. ErrorInvalidRequest ErrorCode = "invalid-request" )
type Event ¶
type Event struct {
Kind EventKind `json:"kind"`
ContentIndex *int `json:"contentIndex,omitempty"`
DeltaText string `json:"deltaText,omitempty"`
Text string `json:"text,omitempty"`
Thinking string `json:"thinking,omitempty"`
Image *ContentBlock `json:"image,omitempty"`
PartialImage *ContentBlock `json:"partialImage,omitempty"`
ToolCall *ToolCall `json:"toolCall,omitempty"`
PartialToolCall *PartialToolCall `json:"partialToolCall,omitempty"`
PartialMessage *AssistantMessage `json:"partialMessage,omitempty"`
FinalMessage *AssistantMessage `json:"finalMessage,omitempty"`
Usage *Usage `json:"usage,omitempty"`
StopReason StopReason `json:"stopReason,omitempty"`
Error string `json:"error,omitempty"`
}
Event is a provider-neutral text-generation stream event.
Content block events may be interleaved. Consumers must route text, thinking, and tool-call updates by ContentIndex instead of assuming events arrive as a single sequential output buffer.
Typical consumers switch on Kind:
switch event.Kind {
case sigma.EventKindTextDelta:
handleTextDelta(event.ContentIndex, event.DeltaText)
case sigma.EventKindToolCallEnd:
handleToolCall(event.ContentIndex, event.ToolCall)
case sigma.EventKindDone, sigma.EventKindError:
finish(event)
}
func (Event) IsTerminal ¶
IsTerminal reports whether event ends a stream.
type EventKind ¶
type EventKind string
EventKind identifies the kind of provider-neutral streaming event.
const ( // EventKindStart marks the beginning of a stream. EventKindStart EventKind = "start" // EventKindTextStart marks the beginning of a text content block. EventKindTextStart EventKind = "text_start" // EventKindTextDelta carries text appended to a text content block. EventKindTextDelta EventKind = "text_delta" // EventKindTextEnd marks the end of a text content block. EventKindTextEnd EventKind = "text_end" // EventKindThinkingStart marks the beginning of a thinking content block. EventKindThinkingStart EventKind = "thinking_start" // EventKindThinkingDelta carries text appended to a thinking content block. EventKindThinkingDelta EventKind = "thinking_delta" // EventKindThinkingEnd marks the end of a thinking content block. EventKindThinkingEnd EventKind = "thinking_end" // EventKindToolCallStart marks the beginning of a tool-call content block. EventKindToolCallStart EventKind = "toolcall_start" // EventKindToolCallDelta carries partial tool-call data. EventKindToolCallDelta EventKind = "toolcall_delta" // EventKindToolCallEnd marks the end of a tool-call content block. EventKindToolCallEnd EventKind = "toolcall_end" // EventKindImageStart marks the beginning of an image content block. EventKindImageStart EventKind = "image_start" // EventKindImageDelta carries partial image content. EventKindImageDelta EventKind = "image_delta" // EventKindImageEnd marks the end of an image content block. EventKindImageEnd EventKind = "image_end" // EventKindDone marks the successful end of a stream. EventKindDone EventKind = "done" // EventKindError marks a stream error. EventKindError EventKind = "error" )
func (EventKind) IsTerminal ¶
IsTerminal reports whether kind ends a stream.
type GenerationError ¶
type GenerationError struct {
Final AssistantMessage
Err error
}
GenerationError carries a final assistant message alongside a terminal error.
func (*GenerationError) Error ¶
func (e *GenerationError) Error() string
func (*GenerationError) FinalMessage ¶
func (e *GenerationError) FinalMessage() (AssistantMessage, bool)
FinalMessage returns the assistant message recorded at stream termination.
func (*GenerationError) String ¶
func (e *GenerationError) String() string
String returns the same diagnostic-safe text as Error.
func (*GenerationError) Unwrap ¶
func (e *GenerationError) Unwrap() error
Unwrap returns the terminal generation error.
type GoogleOptions ¶
GoogleOptions carries Google-specific request options known to the root package without importing provider adapters.
type HTTPAttempt ¶ added in v0.3.0
HTTPAttempt records provider-neutral facts about one HTTP request attempt.
func DoHTTPWithRetryAttempts ¶ added in v0.3.0
func DoHTTPWithRetryAttempts( ctx context.Context, client *http.Client, opts Options, newRequest func(context.Context) (*http.Request, error), providerError func(*http.Response) *ProviderError, hooks ...HTTPResponseHook, ) (*http.Response, []HTTPAttempt, error)
DoHTTPWithRetryAttempts sends a request with sigma's shared HTTP retry policy and returns metadata for every attempted HTTP request.
type HTTPResponseHook ¶
HTTPResponseHook inspects a response before retry status handling. The response body has not been consumed.
func EmbeddingResponseDebugHTTPHook ¶ added in v0.3.0
func EmbeddingResponseDebugHTTPHook(ctx context.Context, opts Options, provider ProviderID, api EmbeddingAPI, model ModelID) HTTPResponseHook
EmbeddingResponseDebugHTTPHook adapts embedding response hooks to the shared retry helper.
func ImageResponseDebugHTTPHook ¶
func ImageResponseDebugHTTPHook(ctx context.Context, opts Options, provider ProviderID, api ImageAPI, model ModelID) HTTPResponseHook
ImageResponseDebugHTTPHook adapts image response hooks to the shared retry helper.
func TextResponseDebugHTTPHook ¶
func TextResponseDebugHTTPHook(ctx context.Context, opts Options, provider ProviderID, api API, model ModelID) HTTPResponseHook
TextResponseDebugHTTPHook adapts text response hooks to the shared retry helper.
type HandoffChange ¶ added in v0.6.0
type HandoffChange struct {
Kind HandoffChangeKind `json:"kind"`
MessageIndex int `json:"messageIndex"`
OutputMessageIndex *int `json:"outputMessageIndex,omitempty"`
ContentIndex *int `json:"contentIndex,omitempty"`
Detail string `json:"detail,omitempty"`
}
HandoffChange describes one source-neutral transformation.
type HandoffChangeKind ¶ added in v0.6.0
type HandoffChangeKind string
HandoffChangeKind identifies one request adaptation made during handoff.
const ( // HandoffChangeThinkingConverted indicates a thinking block was converted // to text for a target that cannot safely replay it natively. HandoffChangeThinkingConverted HandoffChangeKind = "thinking-converted" // HandoffChangeDeveloperRoleConverted indicates a developer message was // converted to a user message for target compatibility. HandoffChangeDeveloperRoleConverted HandoffChangeKind = "developer-role-converted" // HandoffChangeToolResultNameRepaired indicates a missing tool result name // was filled from a prior assistant tool call. HandoffChangeToolResultNameRepaired HandoffChangeKind = "tool-result-name-repaired" // HandoffChangeUnansweredToolCallDropped indicates an assistant tool call // without a matching tool result before the next user/developer turn was // removed. HandoffChangeUnansweredToolCallDropped HandoffChangeKind = "unanswered-tool-call-dropped" // HandoffChangeRepairMessageInserted indicates an assistant bridge message // was inserted between a tool result and following user turn. HandoffChangeRepairMessageInserted HandoffChangeKind = "repair-message-inserted" // HandoffChangeToolResultSynthesized indicates a missing tool result was // synthesized for an unanswered assistant tool call. HandoffChangeToolResultSynthesized HandoffChangeKind = "tool-result-synthesized" // HandoffChangeUnsupportedImageReplaced indicates an image block was // replaced with caller-supplied text for a non-vision target. HandoffChangeUnsupportedImageReplaced HandoffChangeKind = "unsupported-image-replaced" )
type HandoffMessagesResult ¶ added in v0.6.0
type HandoffMessagesResult struct {
Messages []Message `json:"messages,omitempty"`
Report HandoffReport `json:"report,omitempty"`
}
HandoffMessagesResult is a transformed message list and its adaptation report.
func TransformMessagesForModel ¶ added in v0.6.0
func TransformMessagesForModel(target Model, messages []Message, opts ...HandoffOption) (HandoffMessagesResult, error)
TransformMessagesForModel adapts a message list for replay against target. It is equivalent to TransformRequestForModel with only Request.Messages set.
type HandoffOption ¶ added in v0.6.0
type HandoffOption func(*handoffConfig)
HandoffOption configures public cross-provider request adaptation.
func WithHandoffThinkingDelimiters ¶ added in v0.6.0
func WithHandoffThinkingDelimiters(start string, end string) HandoffOption
WithHandoffThinkingDelimiters configures the text wrappers used when provider-native thinking blocks are converted to text.
func WithHandoffUnsupportedImageReplacement ¶ added in v0.6.0
func WithHandoffUnsupportedImageReplacement(text string) HandoffOption
WithHandoffUnsupportedImageReplacement replaces unsupported image blocks with the supplied text instead of returning an unsupported-content error.
type HandoffReport ¶ added in v0.6.0
type HandoffReport struct {
ConvertedThinkingBlocks int `json:"convertedThinkingBlocks,omitempty"`
ConvertedDeveloperMessages int `json:"convertedDeveloperMessages,omitempty"`
RepairedToolResultNames int `json:"repairedToolResultNames,omitempty"`
DroppedUnansweredToolCalls int `json:"droppedUnansweredToolCalls,omitempty"`
InsertedRepairMessages int `json:"insertedRepairMessages,omitempty"`
SynthesizedToolResults int `json:"synthesizedToolResults,omitempty"`
ReplacedUnsupportedImages int `json:"replacedUnsupportedImages,omitempty"`
Changes []HandoffChange `json:"changes,omitempty"`
}
HandoffReport summarizes adaptations made for a target model.
type HandoffResult ¶ added in v0.6.0
type HandoffResult struct {
Request Request `json:"request"`
Report HandoffReport `json:"report,omitempty"`
}
HandoffResult is a transformed request and its adaptation report.
func TransformRequestForModel ¶ added in v0.6.0
func TransformRequestForModel(target Model, req Request, opts ...HandoffOption) (HandoffResult, error)
TransformRequestForModel adapts a request for replay against target. The helper is opt-in and does not mutate the caller's request.
type ImageAPI ¶
type ImageAPI string
ImageAPI identifies an image generation provider API surface.
const ( // ImageAPIOpenAIImages identifies the OpenAI image generation API. ImageAPIOpenAIImages ImageAPI = "openai-images" // ImageAPIOpenRouterImages identifies OpenRouter image generation through Chat Completions. ImageAPIOpenRouterImages ImageAPI = "openrouter-images" // ImageAPIGoogleImages identifies Google's Gemini and Imagen image APIs. ImageAPIGoogleImages ImageAPI = "google-images" // ImageAPIGoogleVertexImages identifies Google's Vertex AI Imagen image API. ImageAPIGoogleVertexImages ImageAPI = "google-vertex-images" )
type ImageError ¶
type ImageError struct {
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
ImageError records a provider-reported image generation error that belongs to a response body rather than the Go error return.
type ImageEvent ¶ added in v0.3.0
type ImageEvent struct {
Kind ImageEventKind `json:"kind"`
Image *ImageInput `json:"image,omitempty"`
PartialImage *ImageInput `json:"partialImage,omitempty"`
FinalImages *AssistantImages `json:"finalImages,omitempty"`
Usage *Usage `json:"usage,omitempty"`
StopReason StopReason `json:"stopReason,omitempty"`
Error string `json:"error,omitempty"`
SequenceIndex *int `json:"sequenceIndex,omitempty"`
}
ImageEvent is a provider-neutral image-generation stream event.
func (ImageEvent) IsTerminal ¶ added in v0.3.0
func (event ImageEvent) IsTerminal() bool
IsTerminal reports whether event ends an image stream.
type ImageEventKind ¶ added in v0.3.0
type ImageEventKind string
ImageEventKind identifies the kind of provider-neutral image stream event.
const ( // ImageEventKindStart marks the beginning of an image stream. ImageEventKindStart ImageEventKind = "start" // ImageEventKindPartial carries a partial generated image. ImageEventKindPartial ImageEventKind = "image_partial" // ImageEventKindImage carries a final generated image. ImageEventKindImage ImageEventKind = "image" // ImageEventKindDone marks the successful end of an image stream. ImageEventKindDone ImageEventKind = "done" // ImageEventKindError marks an image stream error. ImageEventKindError ImageEventKind = "error" )
func (ImageEventKind) IsTerminal ¶ added in v0.3.0
func (kind ImageEventKind) IsTerminal() bool
IsTerminal reports whether kind ends an image stream.
type ImageInput ¶
type ImageInput struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
MIMEType string `json:"mimeType,omitempty"`
Source string `json:"source,omitempty"`
Data string `json:"data,omitempty"`
URL string `json:"url,omitempty"`
}
ImageInput is an image or text input used by image APIs.
func ImageData ¶
func ImageData(mimeType string, data string) ImageInput
ImageData constructs a base64 image input or output for image APIs.
func ImageFileID ¶ added in v0.3.0
func ImageFileID(id string) ImageInput
ImageFileID constructs a provider file reference for image APIs.
func ImageOutputData ¶
func ImageOutputData(mimeType string, data string) ImageInput
ImageOutputData constructs a base64 generated image output.
func ImageOutputURL ¶
func ImageOutputURL(mimeType string, url string) ImageInput
ImageOutputURL constructs a URL-backed generated image output.
func ImageText ¶
func ImageText(text string) ImageInput
ImageText constructs a text input for image APIs.
type ImageModel ¶
type ImageModel struct {
ID ModelID `json:"id"`
Provider ProviderID `json:"provider"`
API ImageAPI `json:"api,omitempty"`
Name string `json:"name,omitempty"`
MaxWidth int `json:"maxWidth,omitempty"`
MaxHeight int `json:"maxHeight,omitempty"`
SupportedSizes []string `json:"supportedSizes,omitempty"`
SupportedFormats []string `json:"supportedFormats,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
ImageModel describes a provider image model available through sigma.
func GetImageModel ¶
func GetImageModel(provider ProviderID, id ModelID) (ImageModel, bool)
GetImageModel returns an image model from the default registry.
func ImageModels ¶
func ImageModels() []ImageModel
ImageModels returns image models from the default registry.
type ImageModelSource ¶ added in v0.6.0
type ImageModelSource interface {
ImageModels(context.Context) ([]ImageModel, error)
}
ImageModelSource lists image models for a provider-owned runtime source.
type ImageModelSourceFunc ¶ added in v0.6.0
type ImageModelSourceFunc func(context.Context) ([]ImageModel, error)
ImageModelSourceFunc adapts a function into an ImageModelSource.
func (ImageModelSourceFunc) ImageModels ¶ added in v0.6.0
func (f ImageModelSourceFunc) ImageModels(ctx context.Context) ([]ImageModel, error)
ImageModels calls f.
type ImageOperation ¶ added in v0.3.0
type ImageOperation string
ImageOperation identifies the requested provider-neutral image operation.
const ( // ImageOperationGenerate requests text-to-image generation. ImageOperationGenerate ImageOperation = "generate" // ImageOperationEdit requests reference-image editing. ImageOperationEdit ImageOperation = "edit" // ImageOperationVariation requests a variation of one source image. ImageOperationVariation ImageOperation = "variation" )
type ImageOption ¶
type ImageOption func(*Options)
ImageOption configures a single image provider request.
Image generation options are intentionally separate from text generation options. Provider adapters still receive the shared internal Options shape so auth, headers, HTTP clients, retry policy, metadata, and provider extension values follow the same conventions as text requests.
func WithImageAPIKey ¶
func WithImageAPIKey(apiKey string) ImageOption
WithImageAPIKey configures a request-scoped image API key override.
func WithImageAuthResolver ¶
func WithImageAuthResolver(resolver AuthResolver) ImageOption
WithImageAuthResolver configures a request-scoped credential resolver.
func WithImageHTTPClient ¶
func WithImageHTTPClient(httpClient *http.Client) ImageOption
WithImageHTTPClient configures the HTTP client exposed to image providers.
func WithImageHeader ¶
func WithImageHeader(key, value string) ImageOption
WithImageHeader adds or replaces an image request header.
func WithImageHeaders ¶
func WithImageHeaders(headers map[string]string) ImageOption
WithImageHeaders adds or replaces image request headers.
func WithImageMaxRetries ¶
func WithImageMaxRetries(maxRetries int) ImageOption
WithImageMaxRetries configures the maximum image provider retry attempts.
func WithImageMaxRetryDelay ¶
func WithImageMaxRetryDelay(maxRetryDelay time.Duration) ImageOption
WithImageMaxRetryDelay configures the maximum delay between image provider retries.
func WithImageMetadata ¶
func WithImageMetadata(metadata map[string]any) ImageOption
WithImageMetadata adds or replaces provider-neutral image request metadata.
func WithImageMetadataValue ¶
func WithImageMetadataValue(key string, value any) ImageOption
WithImageMetadataValue adds or replaces one provider-neutral image metadata value.
func WithImagePayloadDebugHook ¶
func WithImagePayloadDebugHook(hook ImagePayloadDebugHook) ImageOption
WithImagePayloadDebugHook adds a safe image request payload debug hook.
func WithImageProviderAuthResolver ¶
func WithImageProviderAuthResolver(provider ProviderID, resolver AuthResolver) ImageOption
WithImageProviderAuthResolver configures a provider-specific image credential callback.
func WithImageProviderOption ¶
func WithImageProviderOption(provider ProviderID, key string, value any) ImageOption
WithImageProviderOption adds or replaces one advanced provider-specific image value.
func WithImageProviderOptions ¶
func WithImageProviderOptions(provider ProviderID, values map[string]any) ImageOption
WithImageProviderOptions adds or replaces advanced provider-specific image values.
func WithImageResponseDebugHook ¶
func WithImageResponseDebugHook(hook ImageResponseDebugHook) ImageOption
WithImageResponseDebugHook adds a safe image response debug hook.
func WithImageSuppressedHeader ¶ added in v0.6.0
func WithImageSuppressedHeader(key string) ImageOption
WithImageSuppressedHeader removes a final outgoing image request header.
func WithImageSuppressedHeaders ¶ added in v0.6.0
func WithImageSuppressedHeaders(keys ...string) ImageOption
WithImageSuppressedHeaders removes final outgoing image request headers.
func WithImageTimeout ¶
func WithImageTimeout(timeout time.Duration) ImageOption
WithImageTimeout configures the per-request image provider timeout.
type ImagePayloadDebug ¶
type ImagePayloadDebug struct {
Provider ProviderID
API ImageAPI
Model ModelID
Headers http.Header
Payload []byte
PayloadPreview string
}
ImagePayloadDebug is the diagnostic view passed to image payload hooks.
type ImagePayloadDebugHook ¶
type ImagePayloadDebugHook func(context.Context, ImagePayloadDebug) error
ImagePayloadDebugHook inspects a redacted copy of an image provider payload.
Hooks run after provider payload and headers are built and before the HTTP request is sent. Payload replacement is intentionally unsupported: Payload is a redacted copy for diagnostics, so mutating it cannot change the request body or corrupt a later retry attempt.
type ImageProvider ¶
type ImageProvider interface {
API() ImageAPI
Generate(context.Context, ImageModel, ImageRequest, Options) (AssistantImages, error)
}
ImageProvider adapts a provider API into sigma's image generation interface.
type ImageQuality ¶
type ImageQuality string
ImageQuality identifies a provider-neutral generated image quality.
const ( // ImageQualityLow requests a lower-cost image where the provider supports it. ImageQualityLow ImageQuality = "low" // ImageQualityMedium requests a balanced image quality where the provider supports it. ImageQualityMedium ImageQuality = "medium" // ImageQualityHigh requests a higher-quality image where the provider supports it. ImageQualityHigh ImageQuality = "high" )
type ImageRequest ¶
type ImageRequest struct {
Model ModelID `json:"model,omitempty"`
Provider ProviderID `json:"provider,omitempty"`
Operation ImageOperation `json:"operation,omitempty"`
Prompt string `json:"prompt,omitempty"`
Inputs []ImageInput `json:"inputs,omitempty"`
Mask *ImageInput `json:"mask,omitempty"`
Size string `json:"size,omitempty"`
Quality string `json:"quality,omitempty"`
MIMEType string `json:"mimeType,omitempty"`
Count int `json:"count,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
ImageRequest is the provider-neutral input for image generation.
This is separate from image inputs in chat/completion requests. Chat image input uses ContentBlock values built with ImageBase64 or ImageURL; image generation uses ImageInput values and returns AssistantImages.
type ImageResponseDebug ¶
type ImageResponseDebug struct {
Provider ProviderID
API ImageAPI
Model ModelID
StatusCode int
Headers http.Header
RequestID string
}
ImageResponseDebug is the diagnostic view passed to image response hooks.
type ImageResponseDebugHook ¶
type ImageResponseDebugHook func(context.Context, ImageResponseDebug) error
ImageResponseDebugHook inspects redacted image response metadata before the response body is consumed.
type ImageSize ¶
type ImageSize string
ImageSize identifies a provider-neutral generated image size.
const ( // ImageSize1024x1024 requests a square image where the provider supports it. ImageSize1024x1024 ImageSize = "1024x1024" // ImageSize1024x1536 requests a portrait image where the provider supports it. ImageSize1024x1536 ImageSize = "1024x1536" // ImageSize1536x1024 requests a landscape image where the provider supports it. ImageSize1536x1024 ImageSize = "1536x1024" )
type ImageStream ¶ added in v0.3.0
type ImageStream struct {
// contains filtered or unexported fields
}
ImageStream is a single-consumer stream of ordered image provider events.
func StreamImages ¶ added in v0.3.0
func StreamImages(ctx context.Context, model ImageModel, req ImageRequest, opts ...ImageOption) *ImageStream
StreamImages starts a streaming image provider call using the default registry.
func (*ImageStream) Close ¶ added in v0.3.0
func (s *ImageStream) Close()
Close stops the image stream without waiting for a provider terminal event.
func (*ImageStream) Done ¶ added in v0.3.0
func (s *ImageStream) Done() <-chan struct{}
Done closes after Events closes.
func (*ImageStream) Err ¶ added in v0.3.0
func (s *ImageStream) Err() error
Err returns the terminal image stream error, if any.
func (*ImageStream) Events ¶ added in v0.3.0
func (s *ImageStream) Events() <-chan ImageEvent
Events returns the ordered image stream events.
func (*ImageStream) Final ¶ added in v0.3.0
func (s *ImageStream) Final() (AssistantImages, bool)
Final returns the terminal image response, if the stream recorded one.
type ImageStreamWriter ¶ added in v0.3.0
type ImageStreamWriter interface {
Emit(context.Context, ImageEvent) error
Done(context.Context, AssistantImages) error
Error(context.Context, error, AssistantImages) error
Close()
}
ImageStreamWriter is the provider side of an ImageStream.
type InMemoryCredentialStore ¶ added in v0.6.0
type InMemoryCredentialStore struct {
// contains filtered or unexported fields
}
InMemoryCredentialStore is a process-local CredentialStore implementation.
func NewInMemoryCredentialStore ¶ added in v0.6.0
func NewInMemoryCredentialStore() *InMemoryCredentialStore
NewInMemoryCredentialStore constructs an empty in-memory credential store.
func (*InMemoryCredentialStore) DeleteCredential ¶ added in v0.6.0
func (s *InMemoryCredentialStore) DeleteCredential(_ context.Context, provider ProviderID) error
DeleteCredential removes a provider credential.
func (*InMemoryCredentialStore) ModifyCredential ¶ added in v0.6.0
func (s *InMemoryCredentialStore) ModifyCredential(ctx context.Context, provider ProviderID, fn CredentialModifyFunc) (StoredCredential, bool, error)
ModifyCredential serializes read-modify-write operations for one provider.
func (*InMemoryCredentialStore) ReadCredential ¶ added in v0.6.0
func (s *InMemoryCredentialStore) ReadCredential(_ context.Context, provider ProviderID) (StoredCredential, bool, error)
ReadCredential returns a copied credential for provider.
type InMemoryRetrievalIndex ¶ added in v0.3.0
type InMemoryRetrievalIndex struct {
// contains filtered or unexported fields
}
InMemoryRetrievalIndex stores normalized embedding vectors in process memory.
func NewInMemoryRetrievalIndex ¶ added in v0.3.0
func NewInMemoryRetrievalIndex(client *Client, model EmbeddingModel, config InMemoryRetrievalIndexConfig, opts ...EmbeddingOption) *InMemoryRetrievalIndex
NewInMemoryRetrievalIndex constructs an in-memory embedding-backed retrieval index.
func (*InMemoryRetrievalIndex) AddChunks ¶ added in v0.3.0
func (i *InMemoryRetrievalIndex) AddChunks(ctx context.Context, chunks []RetrievalChunk) error
AddChunks embeds and indexes caller-supplied chunks as document inputs.
func (*InMemoryRetrievalIndex) AddDocuments ¶ added in v0.3.0
func (i *InMemoryRetrievalIndex) AddDocuments(ctx context.Context, docs []RetrievalDocument) error
AddDocuments splits, embeds, and indexes documents as document inputs.
func (*InMemoryRetrievalIndex) Search ¶ added in v0.3.0
func (i *InMemoryRetrievalIndex) Search(ctx context.Context, query string, limit int) ([]RetrievalResult, error)
Search embeds query as a query input and returns cosine-ranked chunks.
type InMemoryRetrievalIndexConfig ¶ added in v0.3.0
type InMemoryRetrievalIndexConfig struct {
Splitter RetrievalSplitterConfig
Batch EmbeddingBatchConfig
Dimensions int
}
InMemoryRetrievalIndexConfig configures an in-memory embedding-backed index.
type Message ¶
type Message struct {
Role Role `json:"role"`
Content []ContentBlock `json:"content,omitempty"`
ToolCallID string `json:"toolCallID,omitempty"`
ToolName string `json:"toolName,omitempty"`
AddedToolNames []string `json:"addedToolNames,omitempty"`
IsError bool `json:"isError,omitempty"`
Provider ProviderID `json:"provider,omitempty"`
API API `json:"api,omitempty"`
Model ModelID `json:"model,omitempty"`
StopReason StopReason `json:"stopReason,omitempty"`
Usage *Usage `json:"usage,omitempty"`
}
Message is a conversation message discriminated by Role.
User, developer, and assistant messages use Content. Tool-result messages use Content plus ToolCallID, optional AddedToolNames, and IsError. Provider, API, Model, and StopReason preserve assistant provenance for later cross-provider replay. Go cannot make those role-specific fields impossible to combine in a plain struct, so callers should prefer UserText, UserContent, ToolResult, and ToolError when constructing persisted conversations.
func ToolResult ¶
ToolResult constructs a successful tool-result message.
func UserContent ¶
func UserContent(blocks ...ContentBlock) Message
UserContent constructs a user message from content blocks.
type MistralOptions ¶ added in v0.5.0
type MistralOptions struct {
ToolChoice *MistralToolChoice
}
MistralOptions carries Mistral-specific request options known to the root package without importing the provider adapter.
type MistralToolChoice ¶ added in v0.5.0
type MistralToolChoice struct {
Type MistralToolChoiceType `json:"type"`
Name string `json:"name,omitempty"`
}
MistralToolChoice carries Mistral Conversations tool choice controls.
type MistralToolChoiceType ¶ added in v0.5.0
type MistralToolChoiceType string
MistralToolChoiceType identifies Mistral Conversations tool selection behavior.
const ( // MistralToolChoiceAuto lets Mistral choose whether to call a tool. MistralToolChoiceAuto MistralToolChoiceType = "auto" // MistralToolChoiceAny asks Mistral to call one of the supplied tools. MistralToolChoiceAny MistralToolChoiceType = "any" // MistralToolChoiceNone prevents Mistral from calling tools. MistralToolChoiceNone MistralToolChoiceType = "none" // MistralToolChoiceRequired requires Mistral to call one of the supplied tools. MistralToolChoiceRequired MistralToolChoiceType = "required" // MistralToolChoiceTool requires Mistral to call the named function. MistralToolChoiceTool MistralToolChoiceType = "function" )
type Model ¶
type Model struct {
ID ModelID `json:"id"`
Provider ProviderID `json:"provider"`
API API `json:"api,omitempty"`
Name string `json:"name,omitempty"`
ContextWindow int `json:"contextWindow,omitempty"`
MaxOutputTokens int `json:"maxOutputTokens,omitempty"`
SupportedInputs []ContentBlockType `json:"supportedInputs,omitempty"`
SupportsTools bool `json:"supportsTools,omitempty"`
SupportsThinking bool `json:"supportsThinking,omitempty"`
ThinkingLevels []ThinkingLevel `json:"thinkingLevels,omitempty"`
ThinkingLevelMap map[ThinkingLevel]string `json:"thinkingLevelMap,omitempty"`
UnsupportedThinkingLevels []ThinkingLevel `json:"unsupportedThinkingLevels,omitempty"`
InputCostPerMillion float64 `json:"inputCostPerMillion,omitempty"`
OutputCostPerMillion float64 `json:"outputCostPerMillion,omitempty"`
CacheReadInputCostPerMillion float64 `json:"cacheReadInputCostPerMillion,omitempty"`
CacheWriteInputCostPerMillion float64 `json:"cacheWriteInputCostPerMillion,omitempty"`
CostTiers []ModelCostTier `json:"costTiers,omitempty"`
CostCurrency string `json:"costCurrency,omitempty"`
DefaultTransport Transport `json:"defaultTransport,omitempty"`
// OpenAICompletionsCompat overrides provider/base-URL compatibility
// detection for OpenAI Chat Completions-compatible custom models.
OpenAICompletionsCompat *OpenAICompletionsCompat `json:"openAICompletionsCompat,omitempty"`
// AnthropicMessagesCompat overrides provider/base-URL compatibility
// detection for Anthropic Messages-compatible custom models.
AnthropicMessagesCompat *AnthropicMessagesCompat `json:"anthropicMessagesCompat,omitempty"`
// OpenAIResponsesCompat configures compatibility behavior for OpenAI
// Responses models. Leave nil for the default conservative behavior.
OpenAIResponsesCompat *OpenAIResponsesCompat `json:"openAIResponsesCompat,omitempty"`
// AzureOpenAIResponses configures Azure OpenAI Responses models. Leave nil
// for non-Azure models.
AzureOpenAIResponses *AzureOpenAIResponsesConfig `json:"azureOpenAIResponses,omitempty"`
// OpenAICodexResponses configures OpenAI Codex Responses models. Leave nil
// for non-Codex models.
OpenAICodexResponses *OpenAICodexResponsesConfig `json:"openAICodexResponses,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
Model describes a provider model available through sigma.
func GetModel ¶
func GetModel(provider ProviderID, id ModelID) (Model, bool)
GetModel returns a text model from the default registry.
func Models ¶
func Models(filters ...ModelFilter) []Model
Models returns text models from the default registry matching all filters.
func OpenAICompatibleModel ¶
func OpenAICompatibleModel(config OpenAICompatibleModelConfig) Model
OpenAICompatibleModel constructs metadata for an OpenAI Chat Completions-compatible model. Register the returned model on the same registry as an openai.Provider, then pass that registry to NewClient with WithRegistry for an isolated setup.
func (Model) ProviderThinkingLevel ¶
func (model Model) ProviderThinkingLevel(level ThinkingLevel) (string, bool)
ProviderThinkingLevel returns the provider-specific value for level. If a model only lists supported levels, the provider value is the level text.
func (Model) SupportsDocuments ¶ added in v0.6.0
SupportsDocuments reports whether model accepts document content as input.
func (Model) SupportsImages ¶
SupportsImages reports whether model accepts image content as input.
func (Model) SupportsInput ¶
func (model Model) SupportsInput(kind ContentBlockType) bool
SupportsInput reports whether model metadata allows a request content kind. Models with no explicit input list are treated as text-only for backwards compatibility with earlier metadata.
func (Model) SupportsReasoning ¶
SupportsReasoning reports whether model metadata advertises provider reasoning or thinking support.
func (Model) SupportsThinkingLevel ¶
func (model Model) SupportsThinkingLevel(level ThinkingLevel) bool
SupportsThinkingLevel reports whether level can be requested for model.
type ModelCostTier ¶ added in v0.6.0
type ModelCostTier struct {
InputTokensAbove int `json:"inputTokensAbove"`
InputCostPerMillion float64 `json:"inputCostPerMillion"`
OutputCostPerMillion float64 `json:"outputCostPerMillion"`
CacheReadInputCostPerMillion float64 `json:"cacheReadInputCostPerMillion,omitempty"`
CacheWriteInputCostPerMillion float64 `json:"cacheWriteInputCostPerMillion,omitempty"`
}
ModelCostTier specifies request-wide model rates above an input threshold. The highest strictly exceeded threshold applies to the whole request.
type ModelFilter ¶
ModelFilter reports whether a model should be included in a model list.
type ModelRef ¶
type ModelRef struct {
Provider ProviderID `json:"provider"`
ID ModelID `json:"id"`
}
ModelRef identifies a provider-specific model.
type OAuthAuth ¶ added in v0.6.0
type OAuthAuth struct {
Name string
RefreshBefore time.Duration
Refresh OAuthRefreshFunc
Credential OAuthCredentialFunc
}
OAuthAuth describes a provider OAuth credential flow.
type OAuthCredentialFunc ¶ added in v0.6.0
type OAuthCredentialFunc func(context.Context, Model, Options, StoredCredential) (Credential, error)
OAuthCredentialFunc converts stored OAuth credentials into request credentials.
type OAuthRefreshFunc ¶ added in v0.6.0
type OAuthRefreshFunc func(context.Context, StoredCredential) (StoredCredential, error)
OAuthRefreshFunc refreshes stored OAuth credentials.
type OAuthTokenProvider ¶
OAuthTokenProvider provides OAuth tokens for a provider adapter.
type OAuthTokenProviderFunc ¶
OAuthTokenProviderFunc adapts a function into an OAuthTokenProvider.
func (OAuthTokenProviderFunc) Token ¶
func (f OAuthTokenProviderFunc) Token(ctx context.Context, model Model, opts Options) (Credential, error)
Token calls f.
type OpenAICodexResponsesConfig ¶
type OpenAICodexResponsesConfig struct {
Model string `json:"model,omitempty"`
SupportsToolSearch bool `json:"supportsToolSearch,omitempty"`
}
OpenAICodexResponsesConfig carries Codex-specific Responses metadata. Model is the model name sent to OpenAI when it differs from sigma's model ID.
type OpenAICompatSupport ¶
type OpenAICompatSupport string
OpenAICompatSupport identifies whether an OpenAI-compatible feature is known to be supported by a provider or endpoint.
const ( // OpenAICompatDefault uses provider and endpoint defaults. OpenAICompatDefault OpenAICompatSupport = "" // OpenAICompatSupported forces a compatibility feature on. OpenAICompatSupported OpenAICompatSupport = "supported" // OpenAICompatUnsupported forces a compatibility feature off. OpenAICompatUnsupported OpenAICompatSupport = "unsupported" )
type OpenAICompatibleEmbeddingModelConfig ¶ added in v0.3.0
type OpenAICompatibleEmbeddingModelConfig struct {
ID ModelID
Provider ProviderID
BaseURL string
Name string
Headers map[string]string
DefaultDimensions int
MinDimensions int
MaxDimensions int
MaxInputTokens int
MaxBatchInputs int
MaxBatchBytes int
InputCostPerMillion float64
CostCurrency string
ProviderMetadata map[string]any
}
OpenAICompatibleEmbeddingModelConfig configures OpenAICompatibleEmbeddingModel.
type OpenAICompatibleModelConfig ¶
type OpenAICompatibleModelConfig struct {
ID ModelID
Provider ProviderID
BaseURL string
Name string
Headers map[string]string
ContextWindow int
MaxOutputTokens int
SupportedInputs []ContentBlockType
SupportsTools bool
SupportsThinking bool
ThinkingLevels []ThinkingLevel
ThinkingLevelMap map[ThinkingLevel]string
UnsupportedThinkingLevels []ThinkingLevel
InputCostPerMillion float64
OutputCostPerMillion float64
CacheReadInputCostPerMillion float64
CacheWriteInputCostPerMillion float64
CostTiers []ModelCostTier
CostCurrency string
DefaultTransport Transport
OpenAICompletionsCompat *OpenAICompletionsCompat
ProviderMetadata map[string]any
}
OpenAICompatibleModelConfig configures OpenAICompatibleModel.
type OpenAICompletionsCacheControlFormat ¶
type OpenAICompletionsCacheControlFormat string
OpenAICompletionsCacheControlFormat identifies how prompt cache markers are encoded by an OpenAI Chat Completions-compatible endpoint.
const ( // OpenAICompletionsCacheControlDefault uses provider and endpoint defaults. OpenAICompletionsCacheControlDefault OpenAICompletionsCacheControlFormat = "" // OpenAICompletionsCacheControlUnsupported suppresses cache-control fields. OpenAICompletionsCacheControlUnsupported OpenAICompletionsCacheControlFormat = "unsupported" // OpenAICompletionsCacheControlMessage sends cache_control beside message content. OpenAICompletionsCacheControlMessage OpenAICompletionsCacheControlFormat = "message" // OpenAICompletionsCacheControlContentPart sends cache_control on content parts. OpenAICompletionsCacheControlContentPart OpenAICompletionsCacheControlFormat = "content-part" // OpenAICompletionsCacheControlAnthropic sends Anthropic-style cache markers // on the instruction message, last tool, and last conversation message. OpenAICompletionsCacheControlAnthropic OpenAICompletionsCacheControlFormat = "anthropic" )
type OpenAICompletionsCompat ¶
type OpenAICompletionsCompat struct {
SupportsStore OpenAICompatSupport `json:"supportsStore,omitempty"`
SupportsDeveloperRole OpenAICompatSupport `json:"supportsDeveloperRole,omitempty"`
ReasoningFormat OpenAICompletionsReasoningFormat `json:"reasoningFormat,omitempty"`
SupportsReasoningEffort OpenAICompatSupport `json:"supportsReasoningEffort,omitempty"`
SupportsStreamingUsage OpenAICompatSupport `json:"supportsStreamingUsage,omitempty"`
SupportsStrictTools OpenAICompatSupport `json:"supportsStrictTools,omitempty"`
SupportsRequiredToolChoice OpenAICompatSupport `json:"supportsRequiredToolChoice,omitempty"`
SupportsToolStream OpenAICompatSupport `json:"supportsToolStream,omitempty"`
SupportsGrammarTools OpenAICompatSupport `json:"supportsGrammarTools,omitempty"`
SupportsJSONSchemaResponseFormat OpenAICompatSupport `json:"supportsJSONSchemaResponseFormat,omitempty"`
MaxTokensField OpenAICompletionsMaxTokensField `json:"maxTokensField,omitempty"`
CacheControlFormat OpenAICompletionsCacheControlFormat `json:"cacheControlFormat,omitempty"`
SupportsSessionAffinity OpenAICompatSupport `json:"supportsSessionAffinity,omitempty"`
SupportsLongCacheRetention OpenAICompatSupport `json:"supportsLongCacheRetention,omitempty"`
RequiresToolResultName OpenAICompatSupport `json:"requiresToolResultName,omitempty"`
RequiresAssistantAfterToolResult OpenAICompatSupport `json:"requiresAssistantAfterToolResult,omitempty"`
RequiresToolsForToolHistory OpenAICompatSupport `json:"requiresToolsForToolHistory,omitempty"`
RequiresReasoningContentOnAssistantMessages OpenAICompatSupport `json:"requiresReasoningContentOnAssistantMessages,omitempty"`
OpenRouterRouting *OpenRouterRoutingPreference `json:"openRouterRouting,omitempty"`
VercelAIGatewayRouting *VercelAIGatewayRoutingPreference `json:"vercelAIGatewayRouting,omitempty"`
}
OpenAICompletionsCompat describes Chat Completions compatibility differences for routers and local OpenAI-compatible endpoints. Leave fields at their zero value to use provider or base-URL detection, or set them when registering a custom model to override conservative defaults.
type OpenAICompletionsMaxTokensField ¶
type OpenAICompletionsMaxTokensField string
OpenAICompletionsMaxTokensField identifies the token-limit field name used by an OpenAI Chat Completions-compatible endpoint.
const ( // OpenAICompletionsMaxTokensDefault uses provider and endpoint defaults. OpenAICompletionsMaxTokensDefault OpenAICompletionsMaxTokensField = "" // OpenAICompletionsMaxTokens sends max_tokens. OpenAICompletionsMaxTokens OpenAICompletionsMaxTokensField = "max_tokens" // OpenAICompletionsMaxCompletionTokens sends max_completion_tokens. OpenAICompletionsMaxCompletionTokens OpenAICompletionsMaxTokensField = "max_completion_tokens" )
type OpenAICompletionsReasoningFormat ¶
type OpenAICompletionsReasoningFormat string
OpenAICompletionsReasoningFormat identifies how reasoning effort is encoded by an OpenAI Chat Completions-compatible endpoint.
const ( // OpenAICompletionsReasoningDefault uses provider and endpoint defaults. OpenAICompletionsReasoningDefault OpenAICompletionsReasoningFormat = "" // OpenAICompletionsReasoningUnsupported suppresses reasoning fields. OpenAICompletionsReasoningUnsupported OpenAICompletionsReasoningFormat = "unsupported" // OpenAICompletionsReasoningEffort sends reasoning_effort. OpenAICompletionsReasoningEffort OpenAICompletionsReasoningFormat = "reasoning_effort" // OpenAICompletionsReasoningObject sends a reasoning object. OpenAICompletionsReasoningObject OpenAICompletionsReasoningFormat = "reasoning" // OpenAICompletionsReasoningFireworks sends reasoning_effort for levels // and the Fireworks thinking object for explicit token budgets. OpenAICompletionsReasoningFireworks OpenAICompletionsReasoningFormat = "fireworks" // OpenAICompletionsReasoningDeepSeek sends a thinking object plus // reasoning_effort when reasoning is enabled. OpenAICompletionsReasoningDeepSeek OpenAICompletionsReasoningFormat = "deepseek" // OpenAICompletionsReasoningStringThinking sends a top-level thinking // string such as "none" or a provider-specific level. OpenAICompletionsReasoningStringThinking OpenAICompletionsReasoningFormat = "string-thinking" // OpenAICompletionsReasoningTogether sends Together's reasoning toggle // plus optional reasoning_effort. OpenAICompletionsReasoningTogether OpenAICompletionsReasoningFormat = "together" // OpenAICompletionsReasoningQwen sends a top-level Qwen enable_thinking flag. OpenAICompletionsReasoningQwen OpenAICompletionsReasoningFormat = "qwen" // OpenAICompletionsReasoningZAI sends a Z.ai thinking object with an // enabled or disabled type. OpenAICompletionsReasoningZAI OpenAICompletionsReasoningFormat = "zai" // OpenAICompletionsReasoningAntLing sends Ant Ling's reasoning object only // for explicitly supported effort levels. OpenAICompletionsReasoningAntLing OpenAICompletionsReasoningFormat = "ant-ling" )
type OpenAIGrammar ¶ added in v0.7.0
type OpenAIGrammar struct {
Syntax OpenAIGrammarSyntax `json:"syntax"`
Definition string `json:"definition"`
}
OpenAIGrammar configures an OpenAI custom tool grammar.
type OpenAIGrammarSyntax ¶ added in v0.7.0
type OpenAIGrammarSyntax string
OpenAIGrammarSyntax identifies the grammar format accepted by OpenAI custom tools.
const ( // OpenAIGrammarLark identifies a Lark grammar definition. OpenAIGrammarLark OpenAIGrammarSyntax = "lark" // OpenAIGrammarRegex identifies a regular-expression grammar definition. OpenAIGrammarRegex OpenAIGrammarSyntax = "regex" )
type OpenAIOptions ¶
type OpenAIOptions struct {
ReasoningEffort ThinkingLevel
ReasoningSummary string
ServiceTier string
ToolChoice any
ResponseFormat any
TopLogprobs int
PromptCacheRetention string
ParallelToolCalls *bool
EnableGrammarTools *bool
TextVerbosity string
CodexWebSocketConnectTimeout *time.Duration
}
OpenAIOptions carries OpenAI-specific request options known to the root package without importing provider adapters.
type OpenAIResponsesCompat ¶ added in v0.6.0
type OpenAIResponsesCompat struct {
SupportsToolSearch bool `json:"supportsToolSearch,omitempty"`
SupportsGrammarTools bool `json:"supportsGrammarTools,omitempty"`
SupportsExplicitPromptCacheMode bool `json:"supportsExplicitPromptCacheMode,omitempty"`
SupportsLongCacheRetention OpenAICompatSupport `json:"supportsLongCacheRetention,omitempty"`
SessionAffinityFormat OpenAIResponsesSessionAffinityFormat `json:"sessionAffinityFormat,omitempty"`
}
OpenAIResponsesCompat describes OpenAI Responses API capabilities that vary by model or compatible endpoint.
type OpenAIResponsesSessionAffinityFormat ¶ added in v0.6.0
type OpenAIResponsesSessionAffinityFormat string
OpenAIResponsesSessionAffinityFormat describes how cached Responses requests identify an affinity session.
const ( // OpenAIResponsesSessionAffinityOpenAINoSession sends an OpenAI-compatible // request ID without sending the OpenAI session_id header. OpenAIResponsesSessionAffinityOpenAINoSession OpenAIResponsesSessionAffinityFormat = "openai-nosession" )
type OpenRouterRoutingPreference ¶
type OpenRouterRoutingPreference struct {
Order []string `json:"order,omitempty"`
Only []string `json:"only,omitempty"`
Ignore []string `json:"ignore,omitempty"`
AllowFallbacks *bool `json:"allow_fallbacks,omitempty"`
RequireParameters *bool `json:"require_parameters,omitempty"`
DataCollection string `json:"data_collection,omitempty"`
ZDR *bool `json:"zdr,omitempty"`
EnforceDistillableText *bool `json:"enforce_distillable_text,omitempty"`
Quantizations []string `json:"quantizations,omitempty"`
MaxPrice map[string]any `json:"max_price,omitempty"`
PreferredMinThroughput any `json:"preferred_min_throughput,omitempty"`
PreferredMaxLatency any `json:"preferred_max_latency,omitempty"`
Sort any `json:"sort,omitempty"`
}
OpenRouterRoutingPreference describes OpenRouter's provider routing request body.
type Option ¶
type Option func(*Options)
Option configures a single provider request.
func WithAPIKey ¶
WithAPIKey configures a request-scoped API key override.
API key overrides are intentionally not retained by WithDefaultOptions.
func WithAnthropicOptions ¶
func WithAnthropicOptions(anthropicOptions AnthropicOptions) Option
WithAnthropicOptions configures known Anthropic-specific request options.
func WithAutomaticMaxTokensForContext ¶ added in v0.6.0
WithAutomaticMaxTokensForContext configures dispatch-time max token budgeting from model context metadata and EstimateRequestTokens.
func WithBedrockOptions ¶ added in v0.2.0
func WithBedrockOptions(bedrockOptions BedrockOptions) Option
WithBedrockOptions configures known Bedrock-specific request options.
func WithCacheRetention ¶
func WithCacheRetention(retention CacheRetention) Option
WithCacheRetention configures provider-side prompt cache retention.
func WithGoogleOptions ¶
func WithGoogleOptions(googleOptions GoogleOptions) Option
WithGoogleOptions configures known Google-specific request options.
func WithHeader ¶
WithHeader adds or replaces a request header.
func WithHeaders ¶
WithHeaders adds or replaces request headers.
func WithJSONOutput ¶ added in v0.6.0
func WithJSONOutput() Option
WithJSONOutput asks the provider to return any JSON object.
func WithJSONSchemaOutput ¶ added in v0.6.0
WithJSONSchemaOutput asks the provider to return JSON matching schema.
func WithMaxRetries ¶
WithMaxRetries configures the maximum HTTP provider retry attempts after the first request. The default is DefaultMaxRetries.
func WithMaxRetryDelay ¶
WithMaxRetryDelay configures the maximum delay between HTTP provider retries, including provider Retry-After values. The default is DefaultMaxRetryDelay.
func WithMaxTokens ¶
WithMaxTokens configures the maximum output tokens for a request.
func WithMaxTokensForContext ¶ added in v0.6.0
WithMaxTokensForContext configures MaxTokens from MaxTokensForContext.
If MaxTokensForContext returns zero, this option leaves MaxTokens unset.
func WithMetadata ¶
WithMetadata adds or replaces provider-neutral request metadata.
func WithMetadataValue ¶
WithMetadataValue adds or replaces one provider-neutral metadata value.
func WithMistralOptions ¶ added in v0.5.0
func WithMistralOptions(mistralOptions MistralOptions) Option
WithMistralOptions configures known Mistral-specific request options.
func WithOpenAIOptions ¶
func WithOpenAIOptions(openAIOptions OpenAIOptions) Option
WithOpenAIOptions configures known OpenAI-specific request options.
func WithProviderAuthResolver ¶
func WithProviderAuthResolver(provider ProviderID, resolver AuthResolver) Option
WithProviderAuthResolver configures a provider-specific credential callback.
func WithProviderOption ¶
func WithProviderOption(provider ProviderID, key string, value any) Option
WithProviderOption adds or replaces one advanced provider-specific value.
func WithProviderOptions ¶
func WithProviderOptions(provider ProviderID, values map[string]any) Option
WithProviderOptions adds or replaces advanced provider-specific values.
func WithReasoningBudgetForContext ¶ added in v0.6.0
func WithReasoningBudgetForContext(model Model, req Request, level ThinkingLevel, requestedMaxTokens int) Option
WithReasoningBudgetForContext configures ReasoningLevel, MaxTokens, and ThinkingBudgetTokens from ReasoningBudgetForContext.
If ReasoningBudgetForContext returns zero values, this option only applies the requested reasoning level.
func WithReasoningLevel ¶
func WithReasoningLevel(level ThinkingLevel) Option
WithReasoningLevel configures a provider-neutral reasoning level.
func WithRequestHTTPClient ¶ added in v0.7.0
WithRequestHTTPClient configures an HTTP client for a text request.
A non-nil request client takes precedence over configured client and provider fallback clients. A nil client retains the existing fallback behavior. This option applies to HTTP and SSE dispatch; WebSocket transports keep their existing dialing behavior.
func WithSessionID ¶
WithSessionID configures a provider conversation or response session id.
func WithStructuredOutput ¶ added in v0.6.0
func WithStructuredOutput(output StructuredOutput) Option
WithStructuredOutput requests provider-neutral structured output.
func WithSuppressedHeader ¶ added in v0.6.0
WithSuppressedHeader removes a final outgoing request header by name.
Suppression applies after provider, model, and caller headers are merged. Credential-bearing auth headers are not suppressed.
func WithSuppressedHeaders ¶ added in v0.6.0
WithSuppressedHeaders removes final outgoing request headers by name.
Header names are matched case-insensitively. Empty names are ignored.
func WithTemperature ¶
WithTemperature configures sampling temperature for a request.
func WithTextPayloadDebugHook ¶
func WithTextPayloadDebugHook(hook TextPayloadDebugHook) Option
WithTextPayloadDebugHook adds a safe text request payload debug hook.
Example ¶
package main
import (
"context"
"github.com/wintermi/sigma"
)
func main() {
_ = sigma.WithTextPayloadDebugHook(func(_ context.Context, debug sigma.TextPayloadDebug) error {
_ = debug.PayloadPreview
return nil
})
}
Output:
func WithTextResponseDebugHook ¶
func WithTextResponseDebugHook(hook TextResponseDebugHook) Option
WithTextResponseDebugHook adds a safe text response debug hook.
func WithThinkingBudgetTokens ¶
WithThinkingBudgetTokens configures a provider-neutral thinking budget.
func WithTimeout ¶
WithTimeout configures the per-request provider timeout. Zero disables the request timeout; cancellation still follows the parent context.
func WithTopLogprobs ¶ added in v0.6.0
WithTopLogprobs requests top token log probabilities when the provider API supports them.
func WithTransport ¶
WithTransport configures the provider transport for a request.
type Options ¶
type Options struct {
Temperature *float64
MaxTokens *int
AutomaticMaxTokensForContext *bool
APIKey string
HTTPClient *http.Client
AuthResolver AuthResolver
Transport Transport
CacheRetention CacheRetention
SessionID string
Headers map[string]string
SuppressedHeaders []string
Timeout *time.Duration
MaxRetries *int
MaxRetryDelay *time.Duration
Metadata map[string]any
ReasoningLevel ThinkingLevel
ThinkingBudgetTokens *int
StructuredOutput *StructuredOutput
TopLogprobs int
ProviderOptions map[ProviderID]map[string]any
ProviderAuthResolvers map[ProviderID]AuthResolver
TextPayloadDebugHooks []TextPayloadDebugHook
TextResponseDebugHooks []TextResponseDebugHook
ImagePayloadDebugHooks []ImagePayloadDebugHook
ImageResponseDebugHooks []ImageResponseDebugHook
EmbeddingPayloadDebugHooks []EmbeddingPayloadDebugHook
EmbeddingResponseDebugHooks []EmbeddingResponseDebugHook
OpenAIOptions *OpenAIOptions
AnthropicOptions *AnthropicOptions
GoogleOptions *GoogleOptions
MistralOptions *MistralOptions
BedrockOptions *BedrockOptions
}
Options configures a single provider request.
Client.Stream merges options in this order: client defaults, defaults from the selected model metadata, call options, then provider-specific extension values inside ProviderOptions. Provider packages may define their own helper option functions that populate ProviderOptions without changing this root package.
type PartialToolCall ¶
type PartialToolCall struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ArgumentsDelta string `json:"argumentsDelta,omitempty"`
ProviderSignature string `json:"providerSignature,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
PartialToolCall describes an in-progress tool-call update.
type ProviderAuth ¶ added in v0.6.0
type ProviderAuth struct {
APIKey *APIKeyAuth
OAuth *OAuthAuth
}
ProviderAuth describes supported credential flows for one provider.
type ProviderAuthInfo ¶ added in v0.6.0
type ProviderAuthInfo struct {
ID ProviderID `json:"id"`
APIKey bool `json:"apiKey,omitempty"`
OAuth bool `json:"oauth,omitempty"`
}
ProviderAuthInfo is a copyable view of registered provider auth capabilities.
type ProviderError ¶
type ProviderError struct {
Provider ProviderID
API API
Model ModelID
StatusCode int
RequestID string
ProviderCode string
ProviderMessage string
RetryAfter time.Duration
MaxRetryDelay time.Duration
BodyPreview string
Err error
}
ProviderError reports a failed provider API response without exposing raw payloads.
Provider implementations should map HTTP and provider failures to ProviderError and finish text streams with StopReasonError. Request cancellation should map to ErrAborted and StopReasonAborted instead of ProviderError.
func NewProviderError ¶
func NewProviderError(provider ProviderID, api API, model ModelID, statusCode int, requestID string, retryAfter time.Duration, body []byte, err error) *ProviderError
NewProviderError builds a provider response error with a redacted body preview.
func (*ProviderError) Diagnostic ¶
func (e *ProviderError) Diagnostic() Diagnostic
Diagnostic returns a redacted provider diagnostic suitable for an assistant message that ends with StopReasonError.
func (*ProviderError) Error ¶
func (e *ProviderError) Error() string
func (*ProviderError) Format ¶
func (e *ProviderError) Format(state fmt.State, verb rune)
Format prevents fmt from printing raw ProviderError fields with struct verbs.
func (*ProviderError) Is ¶
func (e *ProviderError) Is(target error) bool
Is supports errors.Is(err, ErrProviderResponse).
func (*ProviderError) String ¶
func (e *ProviderError) String() string
String returns the same diagnostic-safe text as Error.
func (*ProviderError) Unwrap ¶
func (e *ProviderError) Unwrap() error
Unwrap returns the underlying provider cause.
type ProviderID ¶
type ProviderID string
ProviderID identifies a model provider.
const ( // ProviderOpenAI identifies OpenAI. ProviderOpenAI ProviderID = "openai" // ProviderAzureOpenAIResponses identifies Azure OpenAI Responses. ProviderAzureOpenAIResponses ProviderID = "azure-openai-responses" // ProviderOpenAICodex identifies OpenAI Codex. ProviderOpenAICodex ProviderID = "openai-codex" // ProviderAnthropic identifies Anthropic. ProviderAnthropic ProviderID = "anthropic" // ProviderGoogle identifies Google Generative AI. ProviderGoogle ProviderID = "google" // ProviderGoogleVertex identifies Google Vertex AI. ProviderGoogleVertex ProviderID = "google-vertex" // ProviderGoogleVertexOpenAI identifies Vertex AI OpenAI-compatible MaaS. ProviderGoogleVertexOpenAI ProviderID = "google-vertex-openai" // ProviderGoogleVertexAnthropic identifies Anthropic Claude on Vertex AI. ProviderGoogleVertexAnthropic ProviderID = "google-vertex-anthropic" // ProviderMistral identifies Mistral AI. ProviderMistral ProviderID = "mistral" // ProviderRadius identifies the Radius gateway. ProviderRadius ProviderID = "radius" // ProviderAmazonBedrock identifies Amazon Bedrock. ProviderAmazonBedrock ProviderID = "amazon-bedrock" // ProviderOpenRouter identifies OpenRouter. ProviderOpenRouter ProviderID = "openrouter" // ProviderDeepSeek identifies DeepSeek. ProviderDeepSeek ProviderID = "deepseek" // ProviderGroq identifies Groq. ProviderGroq ProviderID = "groq" // ProviderCerebras identifies Cerebras. ProviderCerebras ProviderID = "cerebras" // ProviderXAI identifies xAI. ProviderXAI ProviderID = "xai" // ProviderTogether identifies Together AI. ProviderTogether ProviderID = "together" // ProviderHuggingFace identifies Hugging Face Router. ProviderHuggingFace ProviderID = "huggingface" // ProviderCloudflareAIGateway identifies Cloudflare AI Gateway. ProviderCloudflareAIGateway ProviderID = "cloudflare-ai-gateway" // ProviderCloudflareWorkersAI identifies Cloudflare Workers AI. ProviderCloudflareWorkersAI ProviderID = "cloudflare-workers-ai" // ProviderGitHubCopilot identifies GitHub Copilot. ProviderGitHubCopilot ProviderID = "github-copilot" // ProviderNVIDIA identifies NVIDIA NIM. ProviderNVIDIA ProviderID = "nvidia" // ProviderZAI identifies Z.ai. ProviderZAI ProviderID = "zai" // ProviderZAICodingCN identifies Z.ai Coding CN. ProviderZAICodingCN ProviderID = "zai-coding-cn" // ProviderAntLing identifies Ant Ling. ProviderAntLing ProviderID = "ant-ling" // ProviderMoonshotAI identifies Moonshot AI. ProviderMoonshotAI ProviderID = "moonshotai" // ProviderMoonshotAICN identifies Moonshot AI CN. ProviderMoonshotAICN ProviderID = "moonshotai-cn" // ProviderMiniMax identifies MiniMax. ProviderMiniMax ProviderID = "minimax" // ProviderMiniMaxCN identifies MiniMax CN. ProviderMiniMaxCN ProviderID = "minimax-cn" // ProviderVercelAIGateway identifies Vercel AI Gateway. ProviderVercelAIGateway ProviderID = "vercel-ai-gateway" // ProviderOpenCode identifies OpenCode Zen. ProviderOpenCode ProviderID = "opencode" // ProviderOpenCodeGo identifies OpenCode Go. ProviderOpenCodeGo ProviderID = "opencode-go" // ProviderFireworks identifies Fireworks AI. ProviderFireworks ProviderID = "fireworks" // ProviderFireworksAnthropic identifies Fireworks AI's Anthropic-compatible // Messages endpoint. ProviderFireworksAnthropic ProviderID = "fireworks-anthropic" // ProviderKimi identifies Kimi. ProviderKimi ProviderID = "kimi" // ProviderKimiCoding identifies Kimi Coding. ProviderKimiCoding ProviderID = "kimi-coding" // ProviderXiaomi identifies Xiaomi. ProviderXiaomi ProviderID = "xiaomi" // ProviderXiaomiTokenPlanCN identifies Xiaomi Token Plan CN. ProviderXiaomiTokenPlanCN ProviderID = "xiaomi-token-plan-cn" // ProviderXiaomiTokenPlanAMS identifies Xiaomi Token Plan AMS. ProviderXiaomiTokenPlanAMS ProviderID = "xiaomi-token-plan-ams" // ProviderXiaomiTokenPlanSGP identifies Xiaomi Token Plan SGP. ProviderXiaomiTokenPlanSGP ProviderID = "xiaomi-token-plan-sgp" // ProviderQwenTokenPlan identifies Qwen Token Plan. ProviderQwenTokenPlan ProviderID = "qwen-token-plan" // ProviderQwenTokenPlanCN identifies Qwen Token Plan China. ProviderQwenTokenPlanCN ProviderID = "qwen-token-plan-cn" // ProviderCustom identifies a user-defined provider path. ProviderCustom ProviderID = "custom" )
type ProviderInfo ¶
type ProviderInfo struct {
ID ProviderID `json:"id"`
TextAPI API `json:"textApi,omitempty"`
ImageAPI ImageAPI `json:"imageApi,omitempty"`
EmbeddingAPI EmbeddingAPI `json:"embeddingApi,omitempty"`
}
ProviderInfo is a copyable view of registered provider capabilities.
type ReasoningBudget ¶ added in v0.6.0
type ReasoningBudget struct {
MaxTokens int `json:"maxTokens,omitempty"`
ThinkingBudgetTokens int `json:"thinkingBudgetTokens,omitempty"`
}
ReasoningBudget reports an opt-in output and thinking budget plan.
func ReasoningBudgetForContext ¶ added in v0.6.0
func ReasoningBudgetForContext(model Model, req Request, level ThinkingLevel, requestedMaxTokens int) ReasoningBudget
ReasoningBudgetForContext returns an opt-in max output and thinking budget plan for req, model, and level.
requestedMaxTokens is treated as the caller's desired visible output cap when positive; otherwise model.MaxOutputTokens is used. Non-off reasoning levels reserve a thinking budget inside the final max token cap while preserving at least 1024 visible output tokens when possible. The helper uses EstimateRequestTokens and a fixed safety margin; it does not call provider tokenizers or affect dispatch unless the caller applies the returned values.
type RegisterOption ¶
type RegisterOption func(*registerOptions)
RegisterOption configures registry registration behavior.
func WithMetadataOnly ¶
func WithMetadataOnly() RegisterOption
WithMetadataOnly allows model metadata to be registered without a provider.
func WithOverride ¶
func WithOverride() RegisterOption
WithOverride allows a registration to replace an existing provider or model.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry stores provider implementations and model metadata.
func DefaultRegistry ¶
func DefaultRegistry() *Registry
DefaultRegistry returns a clone of the package-level default registry.
func (*Registry) EmbeddingModel ¶ added in v0.3.0
func (r *Registry) EmbeddingModel(provider ProviderID, id ModelID) (EmbeddingModel, bool)
EmbeddingModel returns an embedding model by provider and model id.
func (*Registry) EmbeddingProvider ¶ added in v0.3.0
func (r *Registry) EmbeddingProvider(id ProviderID) (EmbeddingProvider, bool)
EmbeddingProvider returns the registered embedding provider for id.
func (*Registry) ImageModel ¶
func (r *Registry) ImageModel(provider ProviderID, id ModelID) (ImageModel, bool)
ImageModel returns an image model by provider and model id.
func (*Registry) ImageProvider ¶
func (r *Registry) ImageProvider(id ProviderID) (ImageProvider, bool)
ImageProvider returns the registered image provider for id.
func (*Registry) ListEmbeddingModels ¶ added in v0.3.0
func (r *Registry) ListEmbeddingModels() []EmbeddingModel
ListEmbeddingModels returns embedding models in registration order.
func (*Registry) ListImageModels ¶
func (r *Registry) ListImageModels() []ImageModel
ListImageModels returns image models in registration order.
func (*Registry) ListModels ¶
ListModels returns text models in registration order.
func (*Registry) ListProviderAuths ¶ added in v0.6.0
func (r *Registry) ListProviderAuths() []ProviderAuthInfo
ListProviderAuths returns registered provider auth metadata in registration order.
func (*Registry) ListProviders ¶
func (r *Registry) ListProviders() []ProviderInfo
ListProviders returns providers in first-registration order.
func (*Registry) Model ¶
func (r *Registry) Model(provider ProviderID, id ModelID) (Model, bool)
Model returns a text model by provider and model id.
func (*Registry) ProviderAuth ¶ added in v0.6.0
func (r *Registry) ProviderAuth(provider ProviderID) (ProviderAuth, bool)
ProviderAuth returns registered auth metadata for provider.
func (*Registry) RefreshEmbeddingModels ¶ added in v0.6.0
func (r *Registry) RefreshEmbeddingModels(ctx context.Context, providers ...ProviderID) error
RefreshEmbeddingModels refreshes embedding models from registered runtime sources.
func (*Registry) RefreshImageModels ¶ added in v0.6.0
func (r *Registry) RefreshImageModels(ctx context.Context, providers ...ProviderID) error
RefreshImageModels refreshes image models from registered runtime sources.
func (*Registry) RefreshTextModels ¶ added in v0.6.0
func (r *Registry) RefreshTextModels(ctx context.Context, providers ...ProviderID) error
RefreshTextModels refreshes text models from registered runtime sources.
func (*Registry) RegisterEmbeddingModel ¶ added in v0.3.0
func (r *Registry) RegisterEmbeddingModel(model EmbeddingModel, opts ...RegisterOption) error
RegisterEmbeddingModel registers embedding model metadata.
func (*Registry) RegisterEmbeddingModelSource ¶ added in v0.6.0
func (r *Registry) RegisterEmbeddingModelSource(provider ProviderID, source EmbeddingModelSource, opts ...RegisterOption) error
RegisterEmbeddingModelSource registers a runtime embedding model source for provider.
func (*Registry) RegisterEmbeddingProvider ¶ added in v0.3.0
func (r *Registry) RegisterEmbeddingProvider(id ProviderID, provider EmbeddingProvider, opts ...RegisterOption) error
RegisterEmbeddingProvider registers the implementation for a provider's embeddings API.
func (*Registry) RegisterImageModel ¶
func (r *Registry) RegisterImageModel(model ImageModel, opts ...RegisterOption) error
RegisterImageModel registers image model metadata.
func (*Registry) RegisterImageModelSource ¶ added in v0.6.0
func (r *Registry) RegisterImageModelSource(provider ProviderID, source ImageModelSource, opts ...RegisterOption) error
RegisterImageModelSource registers a runtime image model source for provider.
func (*Registry) RegisterImageProvider ¶
func (r *Registry) RegisterImageProvider(id ProviderID, provider ImageProvider, opts ...RegisterOption) error
RegisterImageProvider registers the implementation for a provider's image API.
func (*Registry) RegisterModel ¶
func (r *Registry) RegisterModel(model Model, opts ...RegisterOption) error
RegisterModel registers text model metadata.
func (*Registry) RegisterProviderAuth ¶ added in v0.6.0
func (r *Registry) RegisterProviderAuth(provider ProviderID, auth ProviderAuth, opts ...RegisterOption) error
RegisterProviderAuth registers auth metadata for provider.
func (*Registry) RegisterTextModelSource ¶ added in v0.6.0
func (r *Registry) RegisterTextModelSource(provider ProviderID, source TextModelSource, opts ...RegisterOption) error
RegisterTextModelSource registers a runtime text model source for provider.
func (*Registry) RegisterTextProvider ¶
func (r *Registry) RegisterTextProvider(id ProviderID, provider TextProvider, opts ...RegisterOption) error
RegisterTextProvider registers the implementation for a provider's text API.
func (*Registry) RestoreTextModels ¶ added in v0.7.0
func (r *Registry) RestoreTextModels(ctx context.Context, providers ...ProviderID) error
RestoreTextModels restores cached text models from registered runtime sources.
When providers are omitted, sources without cached-model support are skipped. An explicitly requested source must implement CachedTextModelSource.
func (*Registry) Snapshot ¶
func (r *Registry) Snapshot() RegistrySnapshot
Snapshot returns a copy of registry providers and model metadata.
func (*Registry) TextProvider ¶
func (r *Registry) TextProvider(id ProviderID) (TextProvider, bool)
TextProvider returns the registered text provider for id.
type RegistrySnapshot ¶
type RegistrySnapshot struct {
Providers []ProviderInfo `json:"providers,omitempty"`
ProviderAuths []ProviderAuthInfo `json:"providerAuths,omitempty"`
Models []Model `json:"models,omitempty"`
ImageModels []ImageModel `json:"imageModels,omitempty"`
EmbeddingModels []EmbeddingModel `json:"embeddingModels,omitempty"`
}
RegistrySnapshot is an immutable-by-convention copy of registry state.
type Request ¶
type Request struct {
SystemPrompt string `json:"systemPrompt,omitempty"`
Messages []Message `json:"messages,omitempty"`
Tools []Tool `json:"tools,omitempty"`
}
Request is the provider-neutral input for a model turn.
func UnmarshalRequest ¶
UnmarshalRequest decodes Request JSON and validates it for replay.
Unknown struct fields are rejected. ProviderMetadata, ToolArguments, and tool schemas remain open JSON maps because providers may need opaque continuation data that sigma does not interpret.
type ResultCitation ¶ added in v0.6.0
type ResultCitation struct {
Type string `json:"type,omitempty"`
ID string `json:"id,omitempty"`
URL string `json:"url,omitempty"`
URI string `json:"uri,omitempty"`
Title string `json:"title,omitempty"`
CitedText string `json:"citedText,omitempty"`
StartIndex *int `json:"startIndex,omitempty"`
EndIndex *int `json:"endIndex,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
ResultCitation is a normalized citation attached to assistant content.
type ResultSource ¶ added in v0.6.0
type ResultSource struct {
Type string `json:"type,omitempty"`
ID string `json:"id,omitempty"`
URL string `json:"url,omitempty"`
URI string `json:"uri,omitempty"`
Title string `json:"title,omitempty"`
StartIndex *int `json:"startIndex,omitempty"`
EndIndex *int `json:"endIndex,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
ResultSource is a normalized source entry reported by a provider response.
type RetrievalChunk ¶ added in v0.3.0
type RetrievalChunk struct {
ID string `json:"id,omitempty"`
DocumentID string `json:"documentID,omitempty"`
Text string `json:"text,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
StartByte int `json:"startByte,omitempty"`
EndByte int `json:"endByte,omitempty"`
}
RetrievalChunk is one indexed text chunk.
func SplitRetrievalDocuments ¶ added in v0.3.0
func SplitRetrievalDocuments(docs []RetrievalDocument, config RetrievalSplitterConfig) ([]RetrievalChunk, error)
SplitRetrievalDocuments splits documents and copies metadata onto each chunk.
func SplitRetrievalText ¶ added in v0.3.0
func SplitRetrievalText(text string, config RetrievalSplitterConfig) ([]RetrievalChunk, error)
SplitRetrievalText splits text into deterministic retrieval chunks.
type RetrievalDocument ¶ added in v0.3.0
type RetrievalDocument struct {
ID string `json:"id,omitempty"`
Text string `json:"text,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
}
RetrievalDocument is caller-owned text plus metadata used for retrieval.
type RetrievalResult ¶ added in v0.3.0
type RetrievalResult struct {
Chunk RetrievalChunk `json:"chunk"`
Score float64 `json:"score"`
}
RetrievalResult is one retrieval hit without exposing stored vectors.
type RetrievalSplitterConfig ¶ added in v0.3.0
type RetrievalSplitterConfig struct {
ChunkSize int `json:"chunkSize,omitempty"`
ChunkOverlap int `json:"chunkOverlap,omitempty"`
Separators []string `json:"separators,omitempty"`
KeepSeparator bool `json:"keepSeparator,omitempty"`
}
RetrievalSplitterConfig configures deterministic character-based splitting.
type RetryHint ¶ added in v0.3.0
RetryHint describes whether retrying the same request may be useful.
type Role ¶
type Role string
Role identifies the role of a persisted conversation message.
const ( // RoleUser identifies a user message. RoleUser Role = "user" // RoleDeveloper identifies provider developer instructions persisted as messages. RoleDeveloper Role = "developer" // RoleAssistant identifies an assistant message. RoleAssistant Role = "assistant" // RoleTool identifies a tool-result message. RoleTool Role = "tool" )
type RouteAction ¶ added in v0.6.0
type RouteAction string
RouteAction is the advised next step after a routed request failed.
const ( // RouteActionRetry advises retrying the same model, waiting RetryAfter // first when it is non-zero. RouteActionRetry RouteAction = "retry" // RouteActionFallback advises sending the request to the advice Model // instead. Use TransformRequestForModel before replaying a conversation // on a different provider. RouteActionFallback RouteAction = "fallback" // RouteActionAbort advises surfacing the error without retrying. RouteActionAbort RouteAction = "abort" )
type RouteAdvice ¶ added in v0.6.0
type RouteAdvice struct {
Action RouteAction
Model ModelRef
RetryAfter time.Duration
Reason string
Classification ErrorClassification
}
RouteAdvice is a deterministic fallback recommendation. Sigma only decides; the caller executes the retry or fallback and tracks attempt state.
type RouteClassification ¶ added in v0.6.0
type RouteClassification struct {
Tier RouteTier `json:"tier"`
Score float64 `json:"score"`
Signals []RouteSignal `json:"signals,omitempty"`
}
RouteClassification is a deterministic complexity classification. Score is the weighted sum of all signals; Signals lists non-zero contributions for observability.
func ClassifyRequest ¶ added in v0.6.0
func ClassifyRequest(req Request, opts ...RouteOption) RouteClassification
ClassifyRequest classifies req into a route tier using weighted rule-based scoring. Classification is pure and deterministic: no model calls, no randomness, and the same request always classifies to the same tier.
Only the system prompt and the latest user message are scored, so prior conversation turns and tool results do not drift long agentic sessions into heavier tiers. Reasoning markers are scored against the user message alone so a system prompt cannot force every request into the reasoning tier. Two or more reasoning markers in the user message classify directly as the reasoning tier unless the dimension weight is zero.
type RouteDecision ¶ added in v0.6.0
type RouteDecision struct {
Model ModelRef `json:"model"`
Tier RouteTier `json:"tier"`
Classification RouteClassification `json:"classification"`
}
RouteDecision reports the model selected for a request and why.
type RouteOption ¶ added in v0.6.0
type RouteOption func(*routeConfig)
RouteOption configures classification and candidate selection.
func WithRouteBoundaries ¶ added in v0.6.0
func WithRouteBoundaries(simpleStandard float64, standardComplex float64, complexReasoning float64) RouteOption
WithRouteBoundaries overrides the ascending tier score boundaries. Scores below simpleStandard classify as simple, below standardComplex as standard, below complexReasoning as complex, and reasoning otherwise.
func WithRouteExclusions ¶ added in v0.6.0
func WithRouteExclusions(refs ...ModelRef) RouteOption
WithRouteExclusions skips the supplied candidates during selection and fallback. Callers own health tracking; models on cooldown should be passed here on every call until the caller considers them healthy again.
func WithRouteModelLookup ¶ added in v0.6.0
func WithRouteModelLookup(lookup func(ModelRef) (Model, bool)) RouteOption
WithRouteModelLookup overrides how candidate metadata is resolved for context-overflow fallback. The default lookup uses DefaultRegistry.
func WithRouteWeight ¶ added in v0.6.0
func WithRouteWeight(dimension string, weight float64) RouteOption
WithRouteWeight overrides the weight of one classifier dimension. Setting a dimension weight to zero removes it from scoring. The tokenCount dimension defaults to zero weight because accumulated agentic context would otherwise bias every late-turn request toward heavier tiers; enable it only for single-turn workloads.
type RoutePolicy ¶ added in v0.6.0
RoutePolicy maps tiers to ordered model candidates. Earlier candidates are preferred. The policy is a plain value constructed by the caller; sigma does not load routing configuration from files or the environment.
func (RoutePolicy) Fallback ¶ added in v0.6.0
func (p RoutePolicy) Fallback(decision RouteDecision, attempted []ModelRef, err error, opts ...RouteOption) RouteAdvice
Fallback classifies err and advises the next step for a failed decision.
The advice is stateless: attempted lists models the caller has already tried, and the failed decision model is always skipped when searching for a fallback candidate. The decision table is:
- invalid-request and unknown errors abort.
- transient errors retry the same model, honoring the provider retry hint.
- rate-limited errors fall back to the next candidate, or retry the same model after the hinted delay when no candidate remains.
- auth, quota, billing, and provider errors fall back to the next candidate, or abort when no candidate remains.
- context-overflow errors fall back to the next candidate with a larger known context window, or abort when none exists.
func (RoutePolicy) Select ¶ added in v0.6.0
func (p RoutePolicy) Select(req Request, opts ...RouteOption) (RouteDecision, error)
Select classifies req and returns the first usable candidate for the classified tier. When the classified tier has no usable candidate the search escalates to more capable tiers first, then falls back to less capable tiers. Candidates excluded via WithRouteExclusions or failing ValidateModelRef are skipped. ErrNoRouteCandidates is returned when no candidate remains.
type RouteSignal ¶ added in v0.6.0
type RouteSignal struct {
Dimension string `json:"dimension"`
Score float64 `json:"score"`
Weight float64 `json:"weight"`
Detail string `json:"detail,omitempty"`
}
RouteSignal is one scored classifier dimension. Score is the raw dimension score in [-1, 1] before weighting.
type RouteTier ¶ added in v0.6.0
type RouteTier string
RouteTier is a deterministic request complexity tier.
const ( // RouteTierSimple identifies short lookups, definitions, and greetings. RouteTierSimple RouteTier = "simple" // RouteTierStandard identifies everyday requests without strong // complexity signals. RouteTierStandard RouteTier = "standard" // RouteTierComplex identifies technical, code-heavy, or multi-part // requests. RouteTierComplex RouteTier = "complex" // RouteTierReasoning identifies requests with explicit deep-reasoning // cues such as step-by-step analysis or trade-off comparisons. RouteTierReasoning RouteTier = "reasoning" )
type Schema ¶
Schema is a JSON Schema-compatible tool parameter definition.
ValidateToolCall supports the subset commonly emitted for model tools: type, properties, required, enum, items, additionalProperties, minimum, maximum, minLength, maxLength, pattern, format, not, if/then/else, and oneOf/anyOf/allOf. It also resolves local JSON Pointer references through $ref, including recursive definitions. ValidateToolCallWithOptions can opt into primitive argument coercion before strict validation. External references and unsupported JSON Schema keywords are rejected or ignored respectively; coercion remains off by default.
type SessionResourceCleanup ¶ added in v0.6.0
SessionResourceCleanup releases cached provider resources for a session.
An empty sessionID asks the cleanup to release all session resources it owns.
type StopReason ¶
type StopReason string
StopReason identifies why a model stopped generating output.
const ( // StopReasonEndTurn indicates the assistant completed a normal turn. StopReasonEndTurn StopReason = "end-turn" // StopReasonMaxTokens indicates generation stopped at the output token limit. StopReasonMaxTokens StopReason = "max-tokens" // StopReasonStopSequence indicates generation stopped after a configured stop sequence. StopReasonStopSequence StopReason = "stop-sequence" // StopReasonToolCalls indicates generation stopped to request tool calls. StopReasonToolCalls StopReason = "tool-calls" // StopReasonContentFilter indicates generation stopped because content was filtered. StopReasonContentFilter StopReason = "content-filter" // StopReasonError indicates generation stopped because the provider returned an error. StopReasonError StopReason = "error" // StopReasonUnknown indicates the provider did not expose a stable stop reason. StopReasonUnknown StopReason = "unknown" )
const ( // StopReasonAborted indicates generation stopped because the stream context was canceled. StopReasonAborted StopReason = "aborted" )
type StoredCredential ¶ added in v0.6.0
type StoredCredential struct {
Type CredentialType
Value string
RefreshToken string
Expiry time.Time
Source string
ProviderEnv map[string]string
Metadata map[string]any
}
StoredCredential is provider-owned authentication material read from a caller-supplied CredentialStore.
type StoredCredentialAuthResolver ¶ added in v0.6.0
type StoredCredentialAuthResolver struct {
Store CredentialStore
Registry *Registry
Fallback AuthResolver
Now func() time.Time
}
StoredCredentialAuthResolver resolves credentials from a CredentialStore.
func (StoredCredentialAuthResolver) Resolve ¶ added in v0.6.0
func (r StoredCredentialAuthResolver) Resolve(ctx context.Context, model Model, opts Options) (Credential, error)
Resolve implements AuthResolver.
func (StoredCredentialAuthResolver) ResolveAuthResolution ¶ added in v0.6.0
func (r StoredCredentialAuthResolver) ResolveAuthResolution(ctx context.Context, model Model, opts Options) (AuthResolution, error)
ResolveAuthResolution implements AuthResolutionResolver.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is a single-consumer stream of ordered provider-neutral events.
Events is single-consumer: callers should have exactly one goroutine receive from it, or coordinate their own fan-out. Close lets a consumer stop early.
func StreamModel ¶
StreamModel starts a provider stream using the default registry.
func (*Stream) Close ¶
func (s *Stream) Close()
Close stops the stream without waiting for a provider terminal event.
func (*Stream) Final ¶
func (s *Stream) Final() (AssistantMessage, bool)
Final returns the terminal assistant message, if the stream recorded one.
type StreamWriter ¶
type StreamWriter interface {
// Emit sends a non-terminal event.
Emit(context.Context, Event) error
// Done sends the single successful terminal event.
Done(context.Context, AssistantMessage) error
// Error sends the single error terminal event.
Error(context.Context, error, AssistantMessage) error
// Close closes the stream without emitting another event.
Close()
}
StreamWriter is the provider side of a Stream.
type StreamingImageProvider ¶ added in v0.3.0
type StreamingImageProvider interface {
ImageProvider
StreamImages(context.Context, ImageModel, ImageRequest, Options) *ImageStream
}
StreamingImageProvider optionally adapts a provider API into sigma's streaming image interface.
type StructuredOutput ¶ added in v0.6.0
type StructuredOutput struct {
Type StructuredOutputType
Name string
Schema any
Strict bool
}
StructuredOutput describes a provider-neutral structured-output request.
type StructuredOutputType ¶ added in v0.6.0
type StructuredOutputType string
StructuredOutputType identifies provider-neutral structured-output modes.
const ( // StructuredOutputJSONObject asks the provider to return any JSON object. StructuredOutputJSONObject StructuredOutputType = "json_object" // StructuredOutputJSONSchema asks the provider to return an object matching // the supplied JSON Schema-compatible schema. StructuredOutputJSONSchema StructuredOutputType = "json_schema" )
type TextModelSource ¶ added in v0.6.0
TextModelSource lists text models for a provider-owned runtime source.
type TextModelSourceFunc ¶ added in v0.6.0
TextModelSourceFunc adapts a function into a TextModelSource.
func (TextModelSourceFunc) TextModels ¶ added in v0.6.0
func (f TextModelSourceFunc) TextModels(ctx context.Context) ([]Model, error)
TextModels calls f.
type TextPayloadDebug ¶
type TextPayloadDebug struct {
Provider ProviderID
API API
Model ModelID
Headers http.Header
Payload []byte
PayloadPreview string
}
TextPayloadDebug is the diagnostic view passed to text payload hooks.
type TextPayloadDebugHook ¶
type TextPayloadDebugHook func(context.Context, TextPayloadDebug) error
TextPayloadDebugHook inspects a redacted copy of a text provider payload.
Hooks run after provider payload and headers are built and before the HTTP request is sent. Payload replacement is intentionally unsupported: Payload is a redacted copy for diagnostics, so mutating it cannot change the request body or corrupt a later retry attempt.
type TextProvider ¶
TextProvider adapts a provider API into sigma's streaming text interface.
type TextResponseDebug ¶
type TextResponseDebug struct {
Provider ProviderID
API API
Model ModelID
StatusCode int
Headers http.Header
RequestID string
}
TextResponseDebug is the diagnostic view passed to text response hooks.
type TextResponseDebugHook ¶
type TextResponseDebugHook func(context.Context, TextResponseDebug) error
TextResponseDebugHook inspects redacted response metadata before the response body is consumed.
type ThinkingLevel ¶
type ThinkingLevel string
ThinkingLevel identifies a provider thinking or reasoning budget level.
const ( // ThinkingLevelOff disables provider reasoning or thinking features. ThinkingLevelOff ThinkingLevel = "off" // ThinkingLevelMinimal requests the smallest provider reasoning or thinking budget. ThinkingLevelMinimal ThinkingLevel = "minimal" // ThinkingLevelLow requests a low reasoning or thinking budget. ThinkingLevelLow ThinkingLevel = "low" // ThinkingLevelMedium requests a medium reasoning or thinking budget. ThinkingLevelMedium ThinkingLevel = "medium" // ThinkingLevelHigh requests a high reasoning or thinking budget. ThinkingLevelHigh ThinkingLevel = "high" // ThinkingLevelXHigh requests the largest provider reasoning or thinking budget. ThinkingLevelXHigh ThinkingLevel = "xhigh" )
type TokenEstimate ¶ added in v0.6.0
type TokenEstimate struct {
Tokens int `json:"tokens"`
UsageTokens int `json:"usageTokens,omitempty"`
TrailingTokens int `json:"trailingTokens,omitempty"`
LastUsageMessageIndex *int `json:"lastUsageMessageIndex,omitempty"`
}
TokenEstimate reports an approximate request token count.
func EstimateRequestTokens ¶ added in v0.6.0
func EstimateRequestTokens(req Request) TokenEstimate
EstimateRequestTokens returns a deterministic approximate token count for a request.
When the latest successful assistant message carries provider-reported usage, the estimate uses that usage as the context anchor and estimates only messages after it. Otherwise it estimates the whole request from the system prompt, tools, and messages.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
// InputSchema accepts Schema, map[string]any, json.RawMessage, []byte, or
// another JSON-marshable value containing a JSON Schema-compatible object.
InputSchema any `json:"inputSchema,omitempty"`
// ProviderDefinedType identifies a server-side provider tool such as web
// search or code execution. When set, supported providers serialize the tool
// using their native tool shape instead of a JSON Schema function tool.
ProviderDefinedType string `json:"providerDefinedType,omitempty"`
ProviderDefinedOptions map[string]any `json:"providerDefinedOptions,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
// OpenAIGrammar configures this tool as an OpenAI Responses custom tool
// when grammar tools are enabled for the request.
OpenAIGrammar *OpenAIGrammar `json:"openAIGrammar,omitempty"`
}
Tool describes a callable model tool.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Name string `json:"name"`
Arguments any `json:"arguments,omitempty"`
ProviderSignature string `json:"providerSignature,omitempty"`
ProviderMetadata map[string]any `json:"providerMetadata,omitempty"`
}
ToolCall describes a model request to invoke a tool.
func (*ToolCall) UnmarshalJSON ¶ added in v0.6.0
type ToolValidationError ¶
type ToolValidationError struct {
ToolName string
Path string
Expected string
Actual string
Reason string
Err error
}
ToolValidationError reports a tool-call argument or tool schema validation failure. Actual is a short, redacted summary safe for logs and tool-result retry messages.
func (*ToolValidationError) Error ¶
func (e *ToolValidationError) Error() string
func (*ToolValidationError) Is ¶
func (e *ToolValidationError) Is(target error) bool
Is supports errors.Is(err, ErrToolValidation).
func (*ToolValidationError) Unwrap ¶
func (e *ToolValidationError) Unwrap() error
Unwrap returns the underlying validation cause.
type ToolValidationOptions ¶ added in v0.6.0
type ToolValidationOptions struct {
// CoercePrimitives converts common model-emitted primitive mismatches on the
// decoded argument copy before strict schema validation.
CoercePrimitives bool
}
ToolValidationOptions configures local tool-call validation.
type Transport ¶
type Transport string
Transport identifies the wire transport used for provider calls.
const ( // TransportHTTP identifies ordinary HTTP request/response transport. TransportHTTP Transport = "http" // TransportSSE identifies server-sent event streaming transport. TransportSSE Transport = "sse" // TransportWebSocket identifies WebSocket streaming transport. TransportWebSocket Transport = "websocket" )
type Usage ¶
type Usage struct {
InputTokens int `json:"inputTokens,omitempty"`
OutputTokens int `json:"outputTokens,omitempty"`
TotalTokens int `json:"totalTokens,omitempty"`
CacheReadInputTokens int `json:"cacheReadInputTokens,omitempty"`
CacheWriteInputTokens int `json:"cacheWriteInputTokens,omitempty"`
LongCacheWriteInputTokens int `json:"longCacheWriteInputTokens,omitempty"`
ThinkingTokens int `json:"thinkingTokens,omitempty"`
ToolUseInputTokens int `json:"toolUseInputTokens,omitempty"`
Provider ProviderID `json:"provider,omitempty"`
Model ModelID `json:"model,omitempty"`
Raw map[string]any `json:"raw,omitempty"`
}
Usage records provider token accounting for a model turn.
func (Usage) Total ¶
Total returns provider-supplied total tokens when available, otherwise it computes a deterministic total from input, output, and prompt-cache token fields. ThinkingTokens is reported separately and should be included in OutputTokens by providers when it is billable as output.
Streaming providers that only receive usage at stream end should leave interim Event.Usage nil and attach the final Usage to the terminal AssistantMessage. The terminal event will then expose the same final usage.
type UsageAccountingOption ¶ added in v0.6.0
type UsageAccountingOption func(*usageAccountingConfig)
UsageAccountingOption configures AccountUsage.
func WithEstimatedCostAdjustment ¶ added in v0.6.0
func WithEstimatedCostAdjustment(adjust func(*Cost)) UsageAccountingOption
WithEstimatedCostAdjustment adjusts Sigma's estimated cost after model pricing has been applied. Providers use this for request-specific pricing modifiers such as service tiers.
func WithProviderReportedCost ¶ added in v0.6.0
func WithProviderReportedCost(cost float64, currency string) UsageAccountingOption
WithProviderReportedCost records a provider-reported cost separately from Sigma's model-metadata estimate.
func WithRawUsage ¶ added in v0.6.0
func WithRawUsage(raw any) UsageAccountingOption
WithRawUsage preserves the provider usage payload as JSON-like debug data.
type VercelAIGatewayRoutingPreference ¶
type VercelAIGatewayRoutingPreference struct {
Order []string `json:"order,omitempty"`
Only []string `json:"only,omitempty"`
Models []string `json:"models,omitempty"`
Caching string `json:"caching,omitempty"`
BYOK map[string]any `json:"byok,omitempty"`
}
VercelAIGatewayRoutingPreference describes Vercel AI Gateway routing values accepted under providerOptions.gateway.
Source Files
¶
- auth.go
- classify.go
- client.go
- credential_store.go
- debug.go
- diagnostics.go
- doc.go
- embedding_models.go
- embedding_models_generated.go
- embeddings.go
- embeddings_embedder.go
- embeddings_vector.go
- errors.go
- estimate.go
- events.go
- handoff.go
- headers.go
- image_models.go
- image_models_generated.go
- image_stream.go
- images.go
- json.go
- models.go
- models_generated.go
- options.go
- persistence.go
- provider.go
- provider_auth.go
- reasoning.go
- registry.go
- results.go
- retrieval.go
- retry.go
- routing.go
- routing_classifier.go
- session_resources.go
- stream.go
- tools.go
- types.go
- usage.go
- validation.go
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
sigma-evals-runner
command
|
|
|
sigma-generate-models
command
|
|
|
sigma-surface-probe
command
|
|
|
examples
|
|
|
cancel
command
|
|
|
chat
command
|
|
|
custom-model
command
|
|
|
fireworks
command
|
|
|
images
command
|
|
|
stream
command
|
|
|
tools
command
|
|
|
internal
|
|
|
evals
Package evals provides repository-internal behavioral evaluation helpers.
|
Package evals provides repository-internal behavioral evaluation helpers. |
|
modeldata
Package modeldata validates the curated snapshot used to generate built-in model metadata.
|
Package modeldata validates the curated snapshot used to generate built-in model metadata. |
|
redact
Package redact contains helpers for removing secrets from diagnostics.
|
Package redact contains helpers for removing secrets from diagnostics. |
|
sse
Package sse parses provider-neutral Server-Sent Event frames.
|
Package sse parses provider-neutral Server-Sent Event frames. |
|
streamstate
Package streamstate contains the serialized state machine backing streams.
|
Package streamstate contains the serialized state machine backing streams. |
|
transform
Package transform will contain provider request and response transforms.
|
Package transform will contain provider request and response transforms. |
|
provider
|
|
|
anthropic
Package anthropic adapts Anthropic Messages-compatible APIs to sigma.
|
Package anthropic adapts Anthropic Messages-compatible APIs to sigma. |
|
antling
Package antling adapts Ant Ling's OpenAI-compatible Chat Completions endpoint to Sigma.
|
Package antling adapts Ant Ling's OpenAI-compatible Chat Completions endpoint to Sigma. |
|
azure
Package azure adapts Azure OpenAI Responses to sigma.
|
Package azure adapts Azure OpenAI Responses to sigma. |
|
bedrock
Package bedrock adapts Amazon Bedrock Converse Stream to sigma.
|
Package bedrock adapts Amazon Bedrock Converse Stream to sigma. |
|
cerebras
Package cerebras adapts Cerebras's OpenAI-compatible Chat Completions endpoint to sigma.
|
Package cerebras adapts Cerebras's OpenAI-compatible Chat Completions endpoint to sigma. |
|
cloudflare
Package cloudflare adapts Cloudflare AI Gateway's compatible text endpoints to sigma.
|
Package cloudflare adapts Cloudflare AI Gateway's compatible text endpoints to sigma. |
|
deepseek
Package deepseek adapts DeepSeek's OpenAI-compatible Chat Completions endpoint to sigma.
|
Package deepseek adapts DeepSeek's OpenAI-compatible Chat Completions endpoint to sigma. |
|
fireworks
Package fireworks adapts Fireworks AI's OpenAI-compatible Chat Completions and Anthropic-compatible Messages endpoints to sigma.
|
Package fireworks adapts Fireworks AI's OpenAI-compatible Chat Completions and Anthropic-compatible Messages endpoints to sigma. |
|
githubcopilot
Package githubcopilot adapts GitHub Copilot's compatible text endpoints to sigma.
|
Package githubcopilot adapts GitHub Copilot's compatible text endpoints to sigma. |
|
google
Package google adapts Google Generative AI and Google Vertex AI to sigma.
|
Package google adapts Google Generative AI and Google Vertex AI to sigma. |
|
groq
Package groq adapts Groq's OpenAI-compatible Chat Completions endpoint to sigma.
|
Package groq adapts Groq's OpenAI-compatible Chat Completions endpoint to sigma. |
|
huggingface
Package huggingface adapts Hugging Face Router's OpenAI-compatible Chat Completions endpoint to sigma.
|
Package huggingface adapts Hugging Face Router's OpenAI-compatible Chat Completions endpoint to sigma. |
|
kimi
Package kimi provides Kimi and Kimi Coding convenience registration over Sigma's Anthropic-compatible Messages adapter.
|
Package kimi provides Kimi and Kimi Coding convenience registration over Sigma's Anthropic-compatible Messages adapter. |
|
minimax
Package minimax adapts MiniMax's Anthropic-compatible Messages endpoints to sigma.
|
Package minimax adapts MiniMax's Anthropic-compatible Messages endpoints to sigma. |
|
mistral
Package mistral adapts the Mistral Conversations API to sigma.
|
Package mistral adapts the Mistral Conversations API to sigma. |
|
moonshot
Package moonshot provides Moonshot AI convenience registration over Sigma's shared OpenAI-compatible Chat Completions provider.
|
Package moonshot provides Moonshot AI convenience registration over Sigma's shared OpenAI-compatible Chat Completions provider. |
|
nvidia
Package nvidia adapts NVIDIA NIM OpenAI-compatible text and embedding endpoints to sigma.
|
Package nvidia adapts NVIDIA NIM OpenAI-compatible text and embedding endpoints to sigma. |
|
openai
Package openai adapts OpenAI-compatible APIs to sigma.
|
Package openai adapts OpenAI-compatible APIs to sigma. |
|
opencode
Package opencode routes OpenCode Zen and OpenCode Go models to the Sigma adapter matching each model's OpenCode API family.
|
Package opencode routes OpenCode Zen and OpenCode Go models to the Sigma adapter matching each model's OpenCode API family. |
|
openrouter
Package openrouter adapts OpenRouter's OpenAI-compatible Chat Completions API to sigma.
|
Package openrouter adapts OpenRouter's OpenAI-compatible Chat Completions API to sigma. |
|
qwen
Package qwen registers Qwen Token Plan OpenAI-compatible text providers.
|
Package qwen registers Qwen Token Plan OpenAI-compatible text providers. |
|
radius
Package radius adapts the Radius gateway messages API to Sigma.
|
Package radius adapts the Radius gateway messages API to Sigma. |
|
together
Package together adapts Together AI's OpenAI-compatible Chat Completions endpoint to sigma.
|
Package together adapts Together AI's OpenAI-compatible Chat Completions endpoint to sigma. |
|
vercel
Package vercel adapts Vercel AI Gateway's Anthropic-compatible Messages endpoint to sigma.
|
Package vercel adapts Vercel AI Gateway's Anthropic-compatible Messages endpoint to sigma. |
|
xai
Package xai adapts xAI's Grok OpenAI-compatible Chat Completions and Responses endpoints to sigma.
|
Package xai adapts xAI's Grok OpenAI-compatible Chat Completions and Responses endpoints to sigma. |
|
xiaomi
Package xiaomi registers Xiaomi MiMo OpenAI-compatible text providers.
|
Package xiaomi registers Xiaomi MiMo OpenAI-compatible text providers. |
|
zai
Package zai registers Z.ai OpenAI-compatible text providers.
|
Package zai registers Z.ai OpenAI-compatible text providers. |
|
Package sigmatest provides deterministic providers and helpers for testing sigma clients without live provider calls.
|
Package sigmatest provides deterministic providers and helpers for testing sigma clients without live provider calls. |