Documentation
¶
Index ¶
- func BatchToGatewayModelAlias(rawModels []string) []string
- func FromGatewayModelAlias(alias string, availableModels []string) string
- func GetAnthropicModels(baseURL, key string) (string, error)
- func GetOpenAIModels(baseURL, apiKey string) (string, error)
- func MapModel(requestedModel string, configuredModel string, availableModels []string) string
- func ToGatewayModelAlias(model string) string
- type AnthropicMessage
- type AnthropicModelResponse
- type AnthropicRequest
- type AnthropicResponse
- type AnthropicThinking
- type AnthropicTool
- type AnthropicToolChoice
- type AnthropicUsage
- type ContentBlock
- type ModelResponse
- type OpenAIChoice
- type OpenAIFunctionCall
- type OpenAIFunctionDef
- type OpenAIImageURL
- type OpenAIMessage
- type OpenAIMessagePart
- type OpenAIRequest
- type OpenAIResponse
- type OpenAIStreamChoice
- type OpenAIStreamChunk
- type OpenAIStreamDelta
- type OpenAITool
- type OpenAIToolCall
- type OpenAIUsage
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 ¶
GetAnthropicModels 通过 API Key 和 BaseURL 获取 Anthropic 模型列表
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 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.
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"`
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 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"`
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"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,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 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 OpenAITool ¶
type OpenAITool struct {
Type string `json:"type"`
Function OpenAIFunctionDef `json:"function"`
}
type OpenAIToolCall ¶
type OpenAIToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function OpenAIFunctionCall `json:"function"`
}