Versions in this module Expand all Collapse all v0 v0.11.0 Jul 5, 2026 Changes in this version + const ContextKeyAIFamily + const ContextKeyChatRequest + const ContextKeyChatResponse + const ContextKeyClientAdapter + const ContextKeyResponseStream + const ContextKeyResponsesRequest + const ContextKeyResponsesResponse + const ContextKeyVirtualModelName + const FamilyChat + const FamilyResponses + const TokensPerMillion + func NewObservedStream(stream io.ReadCloser, observer UsageObserver, metadata UsageMetadata) io.ReadCloser + func RegisterClientAdapter(name string, factory ClientAdapterFactory) + func RegisterLLMAdapter(name string, factory AdapterFactory) + type AIError struct + Code optional.Option[string] + Message string + Param optional.Option[string] + Provider string + StatusCode int + Type string + func (e *AIError) Error() string + type AdapterFactory func(opts LLMAdapterOptions) (LLMAdapter, error) + type AnthropicAdapter struct + func NewAnthropicAdapter(opts LLMAdapterOptions) *AnthropicAdapter + func (a *AnthropicAdapter) Chat(_ context.Context, _ *ChatRequest) (*ChatResponse, error) + func (a *AnthropicAdapter) Name() string + func (a *AnthropicAdapter) Responses(_ context.Context, _ *ResponsesRequest) (*ResponsesResponse, error) + func (a *AnthropicAdapter) StreamChat(_ context.Context, _ *ChatRequest) (io.ReadCloser, error) + func (a *AnthropicAdapter) StreamResponses(_ context.Context, _ *ResponsesRequest) (io.ReadCloser, error) + type ChatRequest struct + Extra *ExtraOptions + MaxTokens *int + Messages []Message + Model string + ParallelToolCalls *bool + Reasoning *Reasoning + ResponseFormat any + Stop []string + Stream bool + StreamOptions *StreamOptions + Temperature *float64 + ToolChoice any + Tools []Tool + TopP *float64 + UnknownFields map[string]any + func (r *ChatRequest) MarshalJSON() ([]byte, error) + func (r *ChatRequest) UnmarshalJSON(data []byte) error + type ChatResponse struct + Choices []Choice + Created int64 + ID string + Model string + Object string + SystemFingerprint string + Usage Usage + type Choice struct + FinishReason string + Index int + Logprobs any + Message Message + type ClientAdapter interface + Name func() string + StreamConverter func(stream io.ReadCloser) io.ReadCloser + ToChatRequest func(body []byte) (*ChatRequest, error) + ToClientChatResponse func(resp *ChatResponse) (any, error) + ToClientError func(err *AIError) (any, error) + ToClientResponsesResponse func(resp *ResponsesResponse) (any, error) + ToResponsesRequest func(body []byte) (*ResponsesRequest, error) + func GetClientAdapter(name string) (ClientAdapter, error) + type ClientAdapterFactory func() ClientAdapter + type CompletionTokensDetails struct + ReasoningTokens int + type ContentPart struct + ImageURL *ImageURL + Text string + Type string + type ExtraOptions struct + AIFamily string + type FunctionCall struct + Arguments string + Name string + type FunctionDesc struct + Description string + Name string + Parameters json.RawMessage + type ImageURL struct + Detail string + URL string + type LLMAdapter interface + Chat func(ctx context.Context, req *ChatRequest) (*ChatResponse, error) + Name func() string + Responses func(ctx context.Context, req *ResponsesRequest) (*ResponsesResponse, error) + StreamChat func(ctx context.Context, req *ChatRequest) (io.ReadCloser, error) + StreamResponses func(ctx context.Context, req *ResponsesRequest) (io.ReadCloser, error) + func GetAdapter(name string, opts LLMAdapterOptions) (LLMAdapter, error) + type LLMAdapterOptions struct + APIKey string + BaseURL string + HTTPClient *client.Client + type Message struct + Content any + Name string + Role string + ToolCallID string + ToolCalls []ToolCall + type ObservedStream struct + func (s *ObservedStream) Read(p []byte) (n int, err error) + type OpenAIChatAdapter struct + func NewOpenAIChatAdapter(opts LLMAdapterOptions) *OpenAIChatAdapter + func (a *OpenAIChatAdapter) Chat(ctx context.Context, chatReq *ChatRequest) (*ChatResponse, error) + func (a *OpenAIChatAdapter) Name() string + func (a *OpenAIChatAdapter) Responses(_ context.Context, _ *ResponsesRequest) (*ResponsesResponse, error) + func (a *OpenAIChatAdapter) StreamChat(ctx context.Context, chatReq *ChatRequest) (io.ReadCloser, error) + func (a *OpenAIChatAdapter) StreamResponses(_ context.Context, _ *ResponsesRequest) (io.ReadCloser, error) + type OpenAIChatClientAdapter struct + func NewOpenAIChatClientAdapter() *OpenAIChatClientAdapter + func (a *OpenAIChatClientAdapter) Name() string + func (a *OpenAIChatClientAdapter) StreamConverter(stream io.ReadCloser) io.ReadCloser + func (a *OpenAIChatClientAdapter) ToChatRequest(body []byte) (*ChatRequest, error) + func (a *OpenAIChatClientAdapter) ToClientChatResponse(resp *ChatResponse) (any, error) + func (a *OpenAIChatClientAdapter) ToClientError(err *AIError) (any, error) + func (a *OpenAIChatClientAdapter) ToClientResponsesResponse(resp *ResponsesResponse) (any, error) + func (a *OpenAIChatClientAdapter) ToResponsesRequest(body []byte) (*ResponsesRequest, error) + type OpenAIErrorDetail struct + Code optional.Option[string] + Message string + Param optional.Option[string] + Type string + type OpenAIErrorResponse struct + Error OpenAIErrorDetail + type PromptTokensDetails struct + CachedTokens int + type Reasoning struct + Effort string + type ResponsesRequest struct + Input []Message + Instructions string + Model string + type ResponsesResponse struct + ID string + Model string + Status string + Usage Usage + type StreamChoice struct + Delta StreamDelta + FinishReason *string + Index int + type StreamChunk struct + Choices []StreamChoice + Created int64 + ID string + Model string + Object string + Usage *Usage + type StreamDelta struct + Content string + ReasoningContent string + Role string + ToolCalls []ToolCall + type StreamOptions struct + IncludeUsage bool + type Tool struct + Function FunctionDesc + Type string + type ToolCall struct + Function FunctionCall + ID string + Type string + type Usage struct + CompletionTokens int + CompletionTokensDetails *CompletionTokensDetails + InputCost float64 + OutputCost float64 + PromptTokens int + PromptTokensDetails *PromptTokensDetails + TotalTokens int + func (u *Usage) CalculateCost(p *config.AIPricingOptions) + type UsageMetadata struct + Model string + Provider string + RouteID string + UserID string + type UsageObserver interface + OnUsage func(ctx context.Context, metadata UsageMetadata, usage Usage)