Documentation
¶
Index ¶
- func BatchToGatewayModelAlias(rawModels []string) []string
- func FromGatewayModelAlias(alias string, availableModels []string) string
- func GetAnthropicModels(baseURL, key string) (string, error)
- func GetAnthropicModelsWithAuth(baseURL, key, authStyle string) (string, error)
- func GetOpenAIModels(baseURL, apiKey string) (string, error)
- func MapModel(requestedModel string, configuredModel string, availableModels []string) string
- func NormalizeAnthropicBaseURLForClaude(baseURL string) string
- func NormalizeAnthropicMessagesURL(baseURL string) string
- func NormalizeAnthropicModelsURL(baseURL string) string
- func NormalizeOpenAIChatCompletionsURL(baseURL string) string
- func NormalizeOpenAIModelsURL(baseURL string) string
- func NormalizeOpenAIResponsesURL(baseURL string) string
- func ProbeOpenAIResponsesSupport(endpoint, apiKey, model string, timeout time.Duration) bool
- func ToGatewayModelAlias(model string) string
- type AnthropicMessage
- type AnthropicModelResponse
- type AnthropicRequest
- type AnthropicResponse
- type AnthropicThinking
- type AnthropicTool
- type AnthropicToolChoice
- type AnthropicUsage
- type ContentBlock
- type ImageSource
- type ModelResponse
- type OpenAIChoice
- type OpenAIFunctionCall
- type OpenAIFunctionDef
- type OpenAIImageURL
- type OpenAIMessage
- type OpenAIMessagePart
- type OpenAIRequest
- type OpenAIResponse
- type OpenAIResponsesRequest
- type OpenAIResponsesResponse
- type OpenAIResponsesTool
- type OpenAIResponsesUsage
- type OpenAIStreamChoice
- type OpenAIStreamChunk
- type OpenAIStreamDelta
- type OpenAIStreamOptions
- type OpenAITool
- type OpenAIToolCall
- type OpenAIUsage
- type ResponsesContentPart
- type ResponsesInputItem
- type ResponsesOutputItem
- type ResponsesOutputPart
- type ResponsesSummaryPart
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromGatewayModelAlias ¶
FromGatewayModelAlias restores the original model name from an obfuscated alias.
func GetAnthropicModels ¶
func GetAnthropicModelsWithAuth ¶ added in v1.2.5
GetAnthropicModelsWithAuth fetches Anthropic-compatible models using either the official x-api-key header or a Bearer token used by some routers.
func GetOpenAIModels ¶
func MapModel ¶
MapModel intelligently translates the requested Anthropic model name into the best available OpenAI gateway counterpart. Uses the authoritative models registry for tier classification and selection when possible, falling back to heuristic keyword matching for models not in the registry.
func NormalizeAnthropicBaseURLForClaude ¶ added in v1.2.5
NormalizeAnthropicBaseURLForClaude returns the base URL shape expected by Claude Code's Anthropic client. Claude appends /v1/messages itself, so a configured endpoint ending in /v1, /v1/messages, or /v1/models would otherwise become /v1/v1/messages at runtime.
func NormalizeAnthropicMessagesURL ¶ added in v1.2.4
func NormalizeAnthropicModelsURL ¶ added in v1.2.4
func NormalizeOpenAIChatCompletionsURL ¶ added in v1.2.4
func NormalizeOpenAIModelsURL ¶ added in v1.2.4
func NormalizeOpenAIResponsesURL ¶ added in v1.2.4
func ProbeOpenAIResponsesSupport ¶ added in v1.2.4
ProbeOpenAIResponsesSupport sends a minimal, real generation request to the /v1/responses endpoint to determine whether an OpenAI-compatible gateway implements the newer, agent-oriented Responses API ("openai(agent)") as opposed to only the legacy Chat Completions API ("openai(chat)"). Listing models alone (/v1/models) cannot distinguish these two, since both protocols commonly share the same model catalog — an actual call to /v1/responses is required. Returns true only when the upstream responds with a 2xx status.
func ToGatewayModelAlias ¶
ToGatewayModelAlias translates a raw model name into an Anthropic-compliant name that avoids Claude Code's hardcoded blacklist.
Types ¶
type AnthropicMessage ¶
type AnthropicModelResponse ¶
type AnthropicRequest ¶
type AnthropicRequest struct {
Model string `json:"model"`
Messages []AnthropicMessage `json:"messages"`
System any `json:"system,omitempty"` // Can be string or []ContentBlock
MaxTokens int `json:"max_tokens,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
StopSequences []string `json:"stop_sequences,omitempty"`
Stream bool `json:"stream,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopK *int `json:"top_k,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Tools []AnthropicTool `json:"tools,omitempty"`
ToolChoice *AnthropicToolChoice `json:"tool_choice,omitempty"`
Thinking *AnthropicThinking `json:"thinking,omitempty"`
}
AnthropicRequest matches the structure sent by Claude Code to /v1/messages.
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,omitempty"`
StopSequence string `json:"stop_sequence,omitempty"`
Usage AnthropicUsage `json:"usage"`
}
AnthropicResponse matches the structure expected by Claude Code.
func ConvertResponse ¶
func ConvertResponse(oaResp *OpenAIResponse) (*AnthropicResponse, error)
ConvertResponse translates a standard OpenAI Chat Completions response to Anthropic style Messages.
func ConvertResponsesResponse ¶ added in v1.2.4
func ConvertResponsesResponse(resp *OpenAIResponsesResponse) (*AnthropicResponse, error)
type AnthropicThinking ¶
type AnthropicTool ¶
type AnthropicTool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"input_schema"` // JSON Schema
}
type AnthropicToolChoice ¶
type AnthropicUsage ¶
type ContentBlock ¶
type ContentBlock struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
Source *ImageSource `json:"source,omitempty"` // for image
ID string `json:"id,omitempty"` // for tool_use
Name string `json:"name,omitempty"` // for tool_use
Input json.RawMessage `json:"input,omitempty"` // for tool_use, can be arbitrary object
Thinking string `json:"thinking,omitempty"` // for thinking
Signature string `json:"signature,omitempty"` // for thinking_delta
ToolUseID string `json:"tool_use_id,omitempty"` // for tool_result
Content any `json:"content,omitempty"` // for tool_result, can be string or []ContentBlock
IsError bool `json:"is_error,omitempty"` // for tool_result
}
type ImageSource ¶ added in v1.2.4
type ModelResponse ¶
type ModelResponse struct {
Data []struct {
Created int `json:"created"`
Domain string `json:"domain"`
Features struct {
StructuredOutputs struct {
JsonObject bool `json:"json_object"`
JsonSchema bool `json:"json_schema"`
} `json:"structured_outputs,omitempty"`
Tools struct {
FunctionCalling bool `json:"function_calling"`
} `json:"tools,omitempty"`
Batch struct {
BatchChat bool `json:"batch_chat"`
BatchJob bool `json:"batch_job"`
} `json:"batch,omitempty"`
Cache struct {
PrefixCache bool `json:"prefix_cache"`
SessionCache bool `json:"session_cache"`
} `json:"cache,omitempty"`
} `json:"features"`
Id string `json:"id"`
Name string `json:"name"`
Object string `json:"object"`
Status string `json:"status,omitempty"`
Version string `json:"version"`
Modalities struct {
InputModalities []string `json:"input_modalities,omitempty"`
OutputModalities []string `json:"output_modalities,omitempty"`
} `json:"modalities,omitempty"`
TaskType []string `json:"task_type,omitempty"`
TokenLimits struct {
ContextWindow int `json:"context_window,omitempty"`
MaxInputTokenLength int `json:"max_input_token_length,omitempty"`
MaxOutputTokenLength int `json:"max_output_token_length,omitempty"`
MaxReasoningTokenLength int `json:"max_reasoning_token_length,omitempty"`
} `json:"token_limits,omitempty"`
} `json:"data"`
Object string `json:"object"`
}
type OpenAIChoice ¶
type OpenAIChoice struct {
Index int `json:"index"`
Message OpenAIMessage `json:"message"`
FinishReason string `json:"finish_reason"`
}
type OpenAIFunctionCall ¶
type OpenAIFunctionDef ¶
type OpenAIFunctionDef struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters,omitempty"` // JSON Schema
}
type OpenAIImageURL ¶
type OpenAIMessage ¶
type OpenAIMessage struct {
Role string `json:"role"`
Content any `json:"content,omitempty"` // string or []OpenAIMessagePart
Name string `json:"name,omitempty"` // for tool result
ToolCallID string `json:"tool_call_id,omitempty"`
ToolCalls []OpenAIToolCall `json:"tool_calls,omitempty"`
FunctionCall *OpenAIFunctionCall `json:"function_call,omitempty"`
Refusal string `json:"refusal,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
}
type OpenAIMessagePart ¶
type OpenAIMessagePart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ImageURL *OpenAIImageURL `json:"image_url,omitempty"`
}
type OpenAIRequest ¶
type OpenAIRequest struct {
Model string `json:"model"`
Messages []OpenAIMessage `json:"messages"`
MaxTokens int `json:"max_tokens,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamOptions *OpenAIStreamOptions `json:"stream_options,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Stop []string `json:"stop,omitempty"`
Tools []OpenAITool `json:"tools,omitempty"`
ToolChoice any `json:"tool_choice,omitempty"` // "none", "auto", or OpenAIToolChoice
}
OpenAIRequest matches the Chat Completions endpoint payload format (/v1/chat/completions).
func ConvertRequest ¶
func ConvertRequest(antReq *AnthropicRequest) (*OpenAIRequest, error)
ConvertRequest maps an Anthropic Messages request to an OpenAI Chat Completions 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"`
}
OpenAIResponse matches the Chat Completions response.
type OpenAIResponsesRequest ¶ added in v1.2.4
type OpenAIResponsesRequest struct {
Model string `json:"model"`
Input []ResponsesInputItem `json:"input"`
Instructions string `json:"instructions,omitempty"`
MaxOutputTokens int `json:"max_output_tokens,omitempty"`
Stream bool `json:"stream,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Tools []OpenAIResponsesTool `json:"tools,omitempty"`
ToolChoice any `json:"tool_choice,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Store *bool `json:"store,omitempty"`
}
OpenAIResponsesRequest matches the OpenAI Responses API payload shape.
func ConvertRequestToResponses ¶ added in v1.2.4
func ConvertRequestToResponses(antReq *AnthropicRequest) (*OpenAIResponsesRequest, error)
type OpenAIResponsesResponse ¶ added in v1.2.4
type OpenAIResponsesResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Model string `json:"model"`
Status string `json:"status"`
Output []ResponsesOutputItem `json:"output"`
Usage OpenAIResponsesUsage `json:"usage"`
}
type OpenAIResponsesTool ¶ added in v1.2.4
type OpenAIResponsesTool struct {
Type string `json:"type"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters,omitempty"`
}
type OpenAIResponsesUsage ¶ added in v1.2.4
type OpenAIStreamChoice ¶
type OpenAIStreamChoice struct {
Index int `json:"index"`
Delta OpenAIStreamDelta `json:"delta"`
FinishReason *string `json:"finish_reason"`
}
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"`
}
OpenAIStreamChunk matches SSE lines returned from OpenAI stream.
type OpenAIStreamDelta ¶
type OpenAIStreamDelta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
ToolCalls []OpenAIToolCall `json:"tool_calls,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
}
type OpenAIStreamOptions ¶ added in v1.2.4
type OpenAIStreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
type OpenAITool ¶
type OpenAITool struct {
Type string `json:"type"`
Function OpenAIFunctionDef `json:"function"`
}
type OpenAIToolCall ¶
type OpenAIToolCall struct {
Index int `json:"index,omitempty"`
ID string `json:"id"`
Type string `json:"type"`
Function OpenAIFunctionCall `json:"function"`
}
type OpenAIUsage ¶
type ResponsesContentPart ¶ added in v1.2.4
type ResponsesInputItem ¶ added in v1.2.4
type ResponsesInputItem struct {
Type string `json:"type"`
Role string `json:"role,omitempty"`
Content any `json:"content,omitempty"`
CallID string `json:"call_id,omitempty"`
Name string `json:"name,omitempty"`
Arguments string `json:"arguments,omitempty"`
Output string `json:"output,omitempty"`
Status string `json:"status,omitempty"`
}
type ResponsesOutputItem ¶ added in v1.2.4
type ResponsesOutputItem struct {
ID string `json:"id"`
Type string `json:"type"`
Role string `json:"role,omitempty"`
Status string `json:"status,omitempty"`
Content []ResponsesOutputPart `json:"content,omitempty"`
CallID string `json:"call_id,omitempty"`
Name string `json:"name,omitempty"`
Arguments string `json:"arguments,omitempty"`
Summary []ResponsesSummaryPart `json:"summary,omitempty"`
}