Documentation
¶
Index ¶
- func AnthropicToOpenAIChat(req *AnthropicMessagesRequest, publicModel string) ([]byte, error)
- func NewOpenAISSEToAnthropicReader(src io.ReadCloser, requestedModel string) io.ReadCloser
- func NewSSEModelRewriteReader(src io.ReadCloser, upstreamModel, alias string) io.ReadCloser
- func OpenAIResponseToAnthropic(body []byte, requestedModel string) ([]byte, error)
- func RewriteModel(b []byte, upstream string) ([]byte, error)
- func RewriteModelAndThinking(b []byte, upstream string, thinkingBudget int) ([]byte, error)
- type AnthropicMessage
- type AnthropicMessagesRequest
- type AnthropicTool
- type ChatMetadata
- type EndpointMetadata
- type ThinkingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AnthropicToOpenAIChat ¶
func AnthropicToOpenAIChat(req *AnthropicMessagesRequest, publicModel string) ([]byte, error)
AnthropicToOpenAIChat converts an Anthropic Messages payload into an OpenAI chat completion payload. The model field is set to publicModel so the gateway's alias routing applies.
func NewOpenAISSEToAnthropicReader ¶
func NewOpenAISSEToAnthropicReader(src io.ReadCloser, requestedModel string) io.ReadCloser
NewOpenAISSEToAnthropicReader translates an OpenAI chat completion SSE stream into the Anthropic Messages SSE event format.
func NewSSEModelRewriteReader ¶
func NewSSEModelRewriteReader(src io.ReadCloser, upstreamModel, alias string) io.ReadCloser
NewSSEModelRewriteReader rewrites the upstream model id to the public alias inside an OpenAI-style SSE stream ("data: {...}" lines), so clients always see the alias they requested — matching the non-streaming response, which rewriteResponseModel already normalizes.
Line-buffered: JSON split across network reads is never touched mid-line, and every other byte (event boundaries, comments, [DONE]) passes through verbatim.
func OpenAIResponseToAnthropic ¶
OpenAIResponseToAnthropic converts a non-streaming OpenAI chat completion JSON document into the Anthropic Messages response format.
Types ¶
type AnthropicMessage ¶
type AnthropicMessage struct {
Role string `json:"role"`
Content json.RawMessage `json:"content"`
}
type AnthropicMessagesRequest ¶
type AnthropicMessagesRequest struct {
Model string `json:"model"`
Messages []AnthropicMessage `json:"messages"`
System json.RawMessage `json:"system,omitempty"`
MaxTokens int `json:"max_tokens,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"top_p,omitempty"`
Stream bool `json:"stream,omitempty"`
Tools []AnthropicTool `json:"tools,omitempty"`
}
func ParseAnthropicMessages ¶
func ParseAnthropicMessages(b []byte) (*AnthropicMessagesRequest, error)
type AnthropicTool ¶
type AnthropicTool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"input_schema,omitempty"`
}
type ChatMetadata ¶
type ChatMetadata struct {
Model string `json:"model"`
Stream bool `json:"stream"`
User string `json:"user"`
Metadata map[string]any `json:"metadata"`
}
func ParseChat ¶
func ParseChat(b []byte) (ChatMetadata, error)
type EndpointMetadata ¶
type EndpointMetadata = ChatMetadata
func ParseEndpoint ¶
func ParseEndpoint(b []byte) (EndpointMetadata, error)