Documentation
¶
Index ¶
- func FilterReasoningForLog(details interface{}) interface{}
- func RecordLLMRequest(userID int64, model string, durationSeconds float64, success bool, ...)
- func RecordLLMRetry(model string)
- type ChatCompletionRequest
- type ChatCompletionResponse
- type Client
- type EmbeddingObject
- type EmbeddingRequest
- type EmbeddingResponse
- type File
- type FilePart
- type ImageConfig
- type ImageOutput
- type ImageURLPart
- type ImageURLValue
- type JSONSchema
- type Message
- type PDFConfig
- type Plugin
- type ReasoningConfig
- type ResponseChoice
- type ResponseFormat
- type ResponseFormatJSONSchema
- type ResponseMessage
- type TextPart
- type Tool
- type ToolCall
- type ToolFunction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterReasoningForLog ¶ added in v0.4.5
func FilterReasoningForLog(details interface{}) interface{}
FilterReasoningForLog filters out encrypted reasoning entries from reasoning_details. Keeps only "reasoning.text" entries which are human-readable and useful for debugging. This prevents massive base64 blobs from polluting logs.
func RecordLLMRequest ¶ added in v0.3.0
func RecordLLMRequest(userID int64, model string, durationSeconds float64, success bool, promptTokens, completionTokens int, cost *float64, jobType string)
RecordLLMRequest записывает метрики LLM запроса. jobType should be "interactive" or "background" (use jobtype.JobType constants).
func RecordLLMRetry ¶ added in v0.3.0
func RecordLLMRetry(model string)
RecordLLMRetry записывает retry-попытку.
Types ¶
type ChatCompletionRequest ¶
type ChatCompletionRequest struct {
Model string `json:"model"`
Messages []Message `json:"messages"`
Plugins []Plugin `json:"plugins,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice any `json:"tool_choice,omitempty"`
ResponseFormat interface{} `json:"response_format,omitempty"`
Reasoning *ReasoningConfig `json:"reasoning,omitempty"`
// Modalities enables image-output models. Use ["image","text"] for Gemini
// image models that return both text and images. Required for image generation;
// see TestAllImageGenerationRequestsSetModalities.
Modalities []string `json:"modalities,omitempty"`
// ImageConfig is model-specific image-generation configuration
// (aspect ratio, size). Only used when Modalities includes "image".
ImageConfig *ImageConfig `json:"image_config,omitempty"`
// UserID is used for metrics tracking only, not sent to API
UserID int64 `json:"-"`
}
type ChatCompletionResponse ¶
type ChatCompletionResponse struct {
ID string `json:"id"`
Model string `json:"model"`
Choices []ResponseChoice `json:"choices"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
Cost *float64 `json:"cost,omitempty"` // Cost in USD from OpenRouter
} `json:"usage"`
// DebugRequestBody contains the raw JSON request body sent to OpenRouter.
// Not part of API response - populated by client for debugging purposes.
DebugRequestBody string `json:"-"`
// DebugResponseBody contains the raw JSON response body from OpenRouter.
// Not part of API response - populated by client for debugging purposes.
DebugResponseBody string `json:"-"`
}
type Client ¶
type Client interface {
CreateChatCompletion(ctx context.Context, req ChatCompletionRequest) (ChatCompletionResponse, error)
CreateEmbeddings(ctx context.Context, req EmbeddingRequest) (EmbeddingResponse, error)
}
type EmbeddingObject ¶
type EmbeddingRequest ¶
type EmbeddingResponse ¶
type EmbeddingResponse struct {
Object string `json:"object"`
Data []EmbeddingObject `json:"data"`
Model string `json:"model"`
Usage struct {
PromptTokens int `json:"prompt_tokens"`
TotalTokens int `json:"total_tokens"`
Cost *float64 `json:"cost,omitempty"` // Cost in USD from OpenRouter
} `json:"usage"`
}
type File ¶
type File struct {
FileName string `json:"filename"`
FileData string `json:"file_data"` // data URL format: "data:mime/type;base64,..."
}
File represents a file for multimodal content (v0.6.0: unified format).
type FilePart ¶
FilePart represents a file part in multimodal messages (v0.6.0: unified format). This is the recommended format for all file types: images, PDFs, audio, video.
type ImageConfig ¶ added in v0.8.0
type ImageConfig struct {
// AspectRatio: "1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9"
// Extended on nano banana: "1:4","4:1","1:8","8:1".
AspectRatio string `json:"aspect_ratio,omitempty"`
// ImageSize: "0.5K" (nano banana only), "1K", "2K", "4K".
ImageSize string `json:"image_size,omitempty"`
}
ImageConfig controls image generation output for models that support it (e.g. google/gemini-3.1-flash-image-preview). Only meaningful when the request sets Modalities to include "image".
type ImageOutput ¶ added in v0.8.0
type ImageOutput struct {
Type string `json:"type"` // "image_url"
ImageURL ImageURLValue `json:"image_url"`
}
ImageOutput represents an image emitted by image-generation models in the response. The URL is a base64 data URL, e.g. "data:image/png;base64,...".
type ImageURLPart ¶ added in v0.8.0
type ImageURLPart struct {
Type string `json:"type"` // "image_url"
ImageURL ImageURLValue `json:"image_url"`
}
ImageURLPart represents an image reference for MODEL INPUT, in the OpenAI-compatible shape. Use this when calling image-generation or image-editing models (e.g. google/gemini-3.1-flash-image-preview) — they reject the "file" FilePart shape with "Invalid file type: image/…". Regular multimodal text models accept either shape, but for image models this is the only format the provider accepts for input images.
type ImageURLValue ¶ added in v0.8.0
type ImageURLValue struct {
URL string `json:"url"`
}
ImageURLValue is the inner object of an ImageOutput; kept as a named type so struct literals can be written without repeating the anonymous shape.
type JSONSchema ¶
type ReasoningConfig ¶ added in v0.4.3
type ReasoningConfig struct {
Effort string `json:"effort,omitempty"` // Gemini 3: "minimal", "low", "medium", "high"
MaxTokens int `json:"max_tokens,omitempty"` // Other models: token budget for reasoning
Exclude bool `json:"exclude,omitempty"` // Suppress reasoning from response
}
ReasoningConfig controls the model's internal reasoning behavior. For Gemini 3: effort levels "minimal", "low", "medium", "high". For other models: max_tokens (1024-128000) controls reasoning depth.
NOTE: response-healing plugin breaks reasoning visibility when combined with json_object format.
type ResponseChoice ¶ added in v0.8.0
type ResponseChoice struct {
Message ResponseMessage `json:"message"`
FinishReason string `json:"finish_reason,omitempty"`
Index int `json:"index"`
}
ResponseChoice is one choice on a ChatCompletionResponse. Named for the same reason as ResponseMessage.
type ResponseFormat ¶
type ResponseFormat struct {
Type string `json:"type"`
JSONSchema *JSONSchema `json:"json_schema,omitempty"`
}
type ResponseFormatJSONSchema ¶
type ResponseFormatJSONSchema struct {
Type string `json:"type"` // "json_schema"
JSONSchema JSONSchema `json:"json_schema"`
}
type ResponseMessage ¶ added in v0.8.0
type ResponseMessage struct {
Role string `json:"role"`
Content string `json:"content"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
Reasoning string `json:"reasoning,omitempty"` // Gemini 3: raw reasoning text
ReasoningDetails interface{} `json:"reasoning_details,omitempty"` // Structured reasoning details
Images []ImageOutput `json:"images,omitempty"` // Generated images (image-output models)
}
ResponseMessage is the assistant message on a ChatCompletionResponse choice. Extracted as a named type so test fixtures and helpers don't have to restate the anonymous struct shape every time a field is added.
type Tool ¶
type Tool struct {
Type string `json:"type"`
Function ToolFunction `json:"function"`
}