protocol

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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

func OpenAIResponseToAnthropic(body []byte, requestedModel string) ([]byte, error)

OpenAIResponseToAnthropic converts a non-streaming OpenAI chat completion JSON document into the Anthropic Messages response format.

func RewriteModel

func RewriteModel(b []byte, upstream string) ([]byte, error)

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)

Jump to

Keyboard shortcuts

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