models

package
v0.14.14 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package models defines request and response types for both Anthropic and OpenAI APIs. These are data-only structs with no business logic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnthropicCountTokensResponse added in v0.12.1

type AnthropicCountTokensResponse struct {
	InputTokens int `json:"input_tokens"`
}

AnthropicCountTokensResponse is the response from the Anthropic Messages count_tokens endpoint.

type AnthropicDelta

type AnthropicDelta struct {
	Type         string `json:"type,omitempty"`
	Text         string `json:"text,omitempty"`
	PartialJSON  string `json:"partial_json,omitempty"`
	StopReason   string `json:"stop_reason,omitempty"`
	StopSequence string `json:"stop_sequence,omitempty"`
	Thinking     string `json:"thinking,omitempty"`
	Signature    string `json:"signature,omitempty"`
}

AnthropicDelta carries incremental updates within a streaming event.

type AnthropicError

type AnthropicError struct {
	Type  string `json:"type"`
	Error struct {
		Type    string `json:"type"`
		Message string `json:"message"`
	} `json:"error"`
}

AnthropicError is the standard error response format for the Anthropic API.

type AnthropicImageSource

type AnthropicImageSource struct {
	Type      string `json:"type"`
	MediaType string `json:"media_type,omitempty"`
	Data      string `json:"data,omitempty"`
	URL       string `json:"url,omitempty"`
}

AnthropicImageSource describes an image content-block source.

type AnthropicMessage

type AnthropicMessage struct {
	Role    string          `json:"role"`
	Content json.RawMessage `json:"content"`
}

AnthropicMessage is a single message in an Anthropic conversation. Content is json.RawMessage because it can be a string or []ContentBlock.

type AnthropicOutputConfig

type AnthropicOutputConfig struct {
	Effort string          `json:"effort,omitempty"`
	Format json.RawMessage `json:"format,omitempty"`
}

AnthropicOutputConfig controls output format and effort level.

type AnthropicRequest

type AnthropicRequest struct {
	Model         string                 `json:"model"`
	Messages      []AnthropicMessage     `json:"messages"`
	MaxTokens     *int                   `json:"max_tokens,omitempty"`
	System        json.RawMessage        `json:"system,omitempty"`
	Stream        bool                   `json:"stream,omitempty"`
	StopSequences []string               `json:"stop_sequences,omitempty"`
	Temperature   *float64               `json:"temperature,omitempty"`
	TopP          *float64               `json:"top_p,omitempty"`
	TopK          *int                   `json:"top_k,omitempty"`
	Tools         []AnthropicTool        `json:"tools,omitempty"`
	ToolChoice    *AnthropicToolChoice   `json:"tool_choice,omitempty"`
	Metadata      json.RawMessage        `json:"metadata,omitempty"`
	Thinking      *AnthropicThinking     `json:"thinking,omitempty"`
	ServiceTier   string                 `json:"service_tier,omitempty"`
	InferenceGeo  string                 `json:"inference_geo,omitempty"`
	OutputConfig  *AnthropicOutputConfig `json:"output_config,omitempty"`
}

AnthropicRequest represents an incoming Anthropic Messages API request.

type AnthropicResponse

type AnthropicResponse struct {
	ID           string         `json:"id"`
	Type         string         `json:"type"`
	Role         string         `json:"role"`
	Content      []ContentBlock `json:"content"`
	Model        string         `json:"model"`
	StopReason   *string        `json:"stop_reason"`
	StopSequence *string        `json:"stop_sequence"`
	Usage        AnthropicUsage `json:"usage"`
}

AnthropicResponse is the non-streaming response from the Anthropic Messages API.

type AnthropicStreamEvent

type AnthropicStreamEvent struct {
	Type         string             `json:"type"`
	Message      *AnthropicResponse `json:"message,omitempty"`
	Index        *int               `json:"index,omitempty"`
	ContentBlock *ContentBlock      `json:"content_block,omitempty"`
	Delta        *AnthropicDelta    `json:"delta,omitempty"`
	Usage        *AnthropicUsage    `json:"usage,omitempty"`
}

AnthropicStreamEvent is a single SSE event in an Anthropic streaming response.

type AnthropicThinking

type AnthropicThinking struct {
	Type         string `json:"type"`
	BudgetTokens *int   `json:"budget_tokens,omitempty"`
}

AnthropicThinking configures extended thinking. Type can be "enabled" (with BudgetTokens), "disabled", or "adaptive".

type AnthropicTool

type AnthropicTool struct {
	Name         string          `json:"name"`
	Description  string          `json:"description,omitempty"`
	InputSchema  json.RawMessage `json:"input_schema"`
	CacheControl json.RawMessage `json:"cache_control,omitempty"`
}

AnthropicTool defines a tool available for the model to call.

type AnthropicToolChoice

type AnthropicToolChoice struct {
	Type                   string `json:"type"`
	Name                   string `json:"name,omitempty"`
	DisableParallelToolUse *bool  `json:"disable_parallel_tool_use,omitempty"`
}

AnthropicToolChoice controls how the model selects tools. Type can be "auto", "any", or "tool" (with Name specifying which tool).

type AnthropicUsage

type AnthropicUsage struct {
	InputTokens              int `json:"input_tokens"`
	OutputTokens             int `json:"output_tokens"`
	CacheCreationInputTokens int `json:"cache_creation_input_tokens,omitempty"`
	CacheReadInputTokens     int `json:"cache_read_input_tokens,omitempty"`
}

AnthropicUsage contains token usage statistics.

type ContentBlock

type ContentBlock struct {
	Type         string                `json:"type"`
	Text         *string               `json:"text,omitempty"`
	Source       *AnthropicImageSource `json:"source,omitempty"`
	ID           string                `json:"id,omitempty"`
	Name         string                `json:"name,omitempty"`
	Input        json.RawMessage       `json:"input,omitempty"`
	ToolUseID    string                `json:"tool_use_id,omitempty"`
	Content      json.RawMessage       `json:"content,omitempty"`
	CacheControl json.RawMessage       `json:"cache_control,omitempty"`
	// Pointer so an EMPTY thinking text still serialises as "thinking":"".
	// omitempty drops an empty string, and clients read the field unconditionally.
	Thinking  *string `json:"thinking,omitempty"`
	Signature string  `json:"signature,omitempty"`
}

ContentBlock represents a typed content block in Anthropic messages. The Type field determines which other fields are populated (text, image, tool_use, tool_result, thinking).

type GeminiCandidate

type GeminiCandidate struct {
	Content      *GeminiContent `json:"content,omitempty"`
	FinishReason string         `json:"finishReason,omitempty"`
	Index        *int           `json:"index,omitempty"`
}

GeminiCandidate is a single candidate in a Gemini response.

type GeminiContent

type GeminiContent struct {
	Role  string       `json:"role,omitempty"`
	Parts []GeminiPart `json:"parts,omitempty"`
}

GeminiContent is a role-tagged list of content parts.

type GeminiCountTokensRequest

type GeminiCountTokensRequest = GeminiGenerateContentRequest

GeminiCountTokensRequest reuses the supported generateContent subset.

type GeminiCountTokensResponse

type GeminiCountTokensResponse struct {
	TotalTokens         int                       `json:"totalTokens"`
	PromptTokensDetails []GeminiTokenCountDetails `json:"promptTokensDetails,omitempty"`
}

GeminiCountTokensResponse is the supported countTokens response shape.

type GeminiError

type GeminiError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Status  string `json:"status"`
}

GeminiError contains the Gemini error body.

type GeminiErrorResponse

type GeminiErrorResponse struct {
	Error GeminiError `json:"error"`
}

GeminiErrorResponse is the Google-style error envelope.

type GeminiFunctionCall

type GeminiFunctionCall struct {
	ID   string          `json:"id,omitempty"`
	Name string          `json:"name"`
	Args json.RawMessage `json:"args,omitempty"`
}

GeminiFunctionCall is a model-issued function call.

type GeminiFunctionCallingConfig

type GeminiFunctionCallingConfig struct {
	Mode                 string   `json:"mode,omitempty"`
	AllowedFunctionNames []string `json:"allowedFunctionNames,omitempty"`
}

GeminiFunctionCallingConfig is the supported function-calling subset.

type GeminiFunctionDeclaration

type GeminiFunctionDeclaration struct {
	Name                 string          `json:"name"`
	Description          string          `json:"description,omitempty"`
	Parameters           json.RawMessage `json:"parameters,omitempty"`
	ParametersJSONSchema json.RawMessage `json:"parametersJsonSchema,omitempty"`
}

GeminiFunctionDeclaration is a tool schema declaration.

type GeminiFunctionResponse

type GeminiFunctionResponse struct {
	ID       string          `json:"id,omitempty"`
	Name     string          `json:"name"`
	Response json.RawMessage `json:"response,omitempty"`
	Parts    json.RawMessage `json:"parts,omitempty"`
}

GeminiFunctionResponse is a user-supplied tool result.

type GeminiGenerateContentRequest

type GeminiGenerateContentRequest struct {
	Model             string                  `json:"model,omitempty"`
	SystemInstruction *GeminiContent          `json:"systemInstruction,omitempty"`
	Contents          []GeminiContent         `json:"contents,omitempty"`
	Tools             []GeminiTool            `json:"tools,omitempty"`
	ToolConfig        *GeminiToolConfig       `json:"toolConfig,omitempty"`
	GenerationConfig  *GeminiGenerationConfig `json:"generationConfig,omitempty"`
	CachedContent     string                  `json:"cachedContent,omitempty"`
	SafetySettings    json.RawMessage         `json:"safetySettings,omitempty"`
}

GeminiGenerateContentRequest is the supported subset of the Gemini generateContent request shape.

type GeminiGenerateContentResponse

type GeminiGenerateContentResponse struct {
	Candidates    []GeminiCandidate    `json:"candidates,omitempty"`
	UsageMetadata *GeminiUsageMetadata `json:"usageMetadata,omitempty"`
}

GeminiGenerateContentResponse is the supported Gemini response envelope.

type GeminiGenerationConfig

type GeminiGenerationConfig struct {
	Temperature        *float64        `json:"temperature,omitempty"`
	TopP               *float64        `json:"topP,omitempty"`
	TopK               *int            `json:"topK,omitempty"`
	MaxOutputTokens    *int            `json:"maxOutputTokens,omitempty"`
	StopSequences      []string        `json:"stopSequences,omitempty"`
	ResponseMimeType   string          `json:"responseMimeType,omitempty"`
	ResponseSchema     json.RawMessage `json:"responseSchema,omitempty"`
	ResponseJSONSchema json.RawMessage `json:"responseJsonSchema,omitempty"`
	ThinkingConfig     json.RawMessage `json:"thinkingConfig,omitempty"`
	CandidateCount     *int            `json:"candidateCount,omitempty"`
	PresencePenalty    *float64        `json:"presencePenalty,omitempty"`
	FrequencyPenalty   *float64        `json:"frequencyPenalty,omitempty"`
	Seed               *int            `json:"seed,omitempty"`
	ResponseModalities json.RawMessage `json:"responseModalities,omitempty"`
	SpeechConfig       json.RawMessage `json:"speechConfig,omitempty"`
	ImageConfig        json.RawMessage `json:"imageConfig,omitempty"`
	MediaResolution    json.RawMessage `json:"mediaResolution,omitempty"`
	ResponseLogprobs   json.RawMessage `json:"responseLogprobs,omitempty"`
	Logprobs           json.RawMessage `json:"logprobs,omitempty"`
}

GeminiGenerationConfig controls sampling and structured output.

type GeminiInlineData

type GeminiInlineData struct {
	MimeType string `json:"mimeType"`
	Data     string `json:"data"`
}

GeminiInlineData is a base64-encoded inline media blob.

type GeminiPart

type GeminiPart struct {
	Text                *string                 `json:"text,omitempty"`
	Thought             *bool                   `json:"thought,omitempty"`
	ThoughtSignature    string                  `json:"thoughtSignature,omitempty"`
	FunctionCall        *GeminiFunctionCall     `json:"functionCall,omitempty"`
	FunctionResponse    *GeminiFunctionResponse `json:"functionResponse,omitempty"`
	InlineData          json.RawMessage         `json:"inlineData,omitempty"`
	FileData            json.RawMessage         `json:"fileData,omitempty"`
	ExecutableCode      json.RawMessage         `json:"executableCode,omitempty"`
	CodeExecutionResult json.RawMessage         `json:"codeExecutionResult,omitempty"`
}

GeminiPart is the supported subset of Gemini content parts.

type GeminiTokenCountDetails

type GeminiTokenCountDetails struct {
	Modality   string `json:"modality"`
	TokenCount int    `json:"tokenCount"`
}

GeminiTokenCountDetails is a modality-specific token count.

type GeminiTool

type GeminiTool struct {
	FunctionDeclarations  []GeminiFunctionDeclaration `json:"functionDeclarations,omitempty"`
	GoogleSearch          json.RawMessage             `json:"googleSearch,omitempty"`
	GoogleSearchRetrieval json.RawMessage             `json:"googleSearchRetrieval,omitempty"`
	URLContext            json.RawMessage             `json:"urlContext,omitempty"`
	CodeExecution         json.RawMessage             `json:"codeExecution,omitempty"`
	GoogleMaps            json.RawMessage             `json:"googleMaps,omitempty"`
	ComputerUse           json.RawMessage             `json:"computerUse,omitempty"`
	EnterpriseWebSearch   json.RawMessage             `json:"enterpriseWebSearch,omitempty"`
}

GeminiTool is the supported subset of Gemini tool declarations.

type GeminiToolConfig

type GeminiToolConfig struct {
	FunctionCallingConfig *GeminiFunctionCallingConfig `json:"functionCallingConfig,omitempty"`
}

GeminiToolConfig configures tool selection.

type GeminiUsageMetadata

type GeminiUsageMetadata struct {
	PromptTokenCount     int                       `json:"promptTokenCount,omitempty"`
	CandidatesTokenCount int                       `json:"candidatesTokenCount,omitempty"`
	TotalTokenCount      int                       `json:"totalTokenCount,omitempty"`
	PromptTokensDetails  []GeminiTokenCountDetails `json:"promptTokensDetails,omitempty"`
}

GeminiUsageMetadata holds token usage for Gemini responses.

type OpenAIChoice

type OpenAIChoice struct {
	Index        int           `json:"index"`
	Message      OpenAIMessage `json:"message"`
	FinishReason *string       `json:"finish_reason,omitempty"`
}

OpenAIChoice is a single completion choice in an OpenAI response.

type OpenAICompletionTokensDetails added in v0.12.2

type OpenAICompletionTokensDetails struct {
	ReasoningTokens int `json:"reasoning_tokens,omitempty"`
}

OpenAICompletionTokensDetails contains completion-token detail breakdowns.

type OpenAIContentPart

type OpenAIContentPart struct {
	Type     string          `json:"type"`
	Text     *string         `json:"text,omitempty"`
	ImageURL *OpenAIImageURL `json:"image_url,omitempty"`
}

OpenAIContentPart is a multimodal content part in a chat message.

type OpenAIFunction

type OpenAIFunction struct {
	Name        string          `json:"name"`
	Description string          `json:"description,omitempty"`
	Parameters  json.RawMessage `json:"parameters,omitempty"`
	Strict      *bool           `json:"strict,omitempty"`
}

OpenAIFunction describes a function the model may call.

type OpenAIFunctionCall

type OpenAIFunctionCall struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments"`
}

OpenAIFunctionCall contains the function name and arguments for a tool call.

type OpenAIImageURL

type OpenAIImageURL struct {
	URL    string `json:"url"`
	Detail string `json:"detail,omitempty"`
}

OpenAIImageURL describes an image input referenced by URL or data URL.

type OpenAIMessage

type OpenAIMessage struct {
	Role                string           `json:"role,omitempty"`
	Content             json.RawMessage  `json:"content,omitempty"`
	Refusal             json.RawMessage  `json:"refusal,omitempty"`
	Name                string           `json:"name,omitempty"`
	ToolCalls           []OpenAIToolCall `json:"tool_calls,omitempty"`
	ToolCallID          string           `json:"tool_call_id,omitempty"`
	CopilotCacheControl json.RawMessage  `json:"copilot_cache_control,omitempty"`
}

OpenAIMessage is a single message in an OpenAI conversation.

type OpenAIPromptTokensDetails added in v0.12.2

type OpenAIPromptTokensDetails struct {
	CachedTokens int `json:"cached_tokens,omitempty"`
}

OpenAIPromptTokensDetails contains prompt-token detail breakdowns.

type OpenAIRequest

type OpenAIRequest struct {
	Model               string          `json:"model"`
	Messages            []OpenAIMessage `json:"messages"`
	MaxTokens           *int            `json:"max_tokens,omitempty"`
	MaxCompletionTokens *int            `json:"max_completion_tokens,omitempty"`
	Temperature         *float64        `json:"temperature,omitempty"`
	TopP                *float64        `json:"top_p,omitempty"`
	N                   *int            `json:"n,omitempty"`
	Stream              *bool           `json:"stream,omitempty"`
	StreamOptions       *StreamOptions  `json:"stream_options,omitempty"`
	Stop                json.RawMessage `json:"stop,omitempty"`
	PresencePenalty     *float64        `json:"presence_penalty,omitempty"`
	FrequencyPenalty    *float64        `json:"frequency_penalty,omitempty"`
	LogitBias           json.RawMessage `json:"logit_bias,omitempty"`
	User                string          `json:"user,omitempty"`
	Tools               []OpenAITool    `json:"tools,omitempty"`
	ToolChoice          json.RawMessage `json:"tool_choice,omitempty"`
	ParallelToolCalls   *bool           `json:"parallel_tool_calls,omitempty"`
	ReasoningEffort     string          `json:"reasoning_effort,omitempty"`
	ResponseFormat      json.RawMessage `json:"response_format,omitempty"`
	Seed                *int            `json:"seed,omitempty"`
}

OpenAIRequest represents an OpenAI Chat Completions API request.

type OpenAIResponse

type OpenAIResponse struct {
	ID                string          `json:"id"`
	Object            string          `json:"object"`
	Created           int64           `json:"created"`
	Model             string          `json:"model"`
	Choices           []OpenAIChoice  `json:"choices"`
	Usage             *OpenAIUsage    `json:"usage,omitempty"`
	SystemFingerprint string          `json:"system_fingerprint,omitempty"`
	CopilotUsage      json.RawMessage `json:"copilot_usage,omitempty"`
}

OpenAIResponse is the non-streaming response from the OpenAI Chat Completions API.

type OpenAIStreamChoice

type OpenAIStreamChoice struct {
	Index        int           `json:"index"`
	Delta        OpenAIMessage `json:"delta"`
	FinishReason *string       `json:"finish_reason,omitempty"`
}

OpenAIStreamChoice is a single choice within a streaming chunk.

type OpenAIStreamChunk

type OpenAIStreamChunk struct {
	ID                string               `json:"id"`
	Object            string               `json:"object"`
	Created           int64                `json:"created"`
	Model             string               `json:"model"`
	Choices           []OpenAIStreamChoice `json:"choices"`
	Usage             *OpenAIUsage         `json:"usage,omitempty"`
	SystemFingerprint string               `json:"system_fingerprint,omitempty"`
	CopilotUsage      json.RawMessage      `json:"copilot_usage,omitempty"`
}

OpenAIStreamChunk is a single SSE chunk in an OpenAI streaming response.

type OpenAITool

type OpenAITool struct {
	Type                string          `json:"type"`
	Function            OpenAIFunction  `json:"function"`
	CopilotCacheControl json.RawMessage `json:"copilot_cache_control,omitempty"`
}

OpenAITool defines a tool (function) available for the model to call.

type OpenAIToolCall

type OpenAIToolCall struct {
	ID       string             `json:"id,omitempty"`
	Type     string             `json:"type,omitempty"`
	Function OpenAIFunctionCall `json:"function"`
	Index    *int               `json:"index,omitempty"`
}

OpenAIToolCall represents a tool call made by the model.

type OpenAIUsage

type OpenAIUsage struct {
	PromptTokens            int                            `json:"prompt_tokens"`
	CompletionTokens        int                            `json:"completion_tokens"`
	TotalTokens             int                            `json:"total_tokens"`
	ReasoningTokens         int                            `json:"reasoning_tokens,omitempty"`
	PromptTokensDetails     *OpenAIPromptTokensDetails     `json:"prompt_tokens_details,omitempty"`
	CompletionTokensDetails *OpenAICompletionTokensDetails `json:"completion_tokens_details,omitempty"`
}

OpenAIUsage contains token usage statistics.

type StreamOptions

type StreamOptions struct {
	IncludeUsage bool `json:"include_usage"`
}

StreamOptions controls streaming behavior, such as including usage stats.

Jump to

Keyboard shortcuts

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