{"modulePath":"github.com/Rethinger/2papi","version":"v0.4.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package protocol\n\n## Functions\n\n```go\nfunc AnthropicToOpenAIChat(req *AnthropicMessagesRequest, publicModel string) ([]byte, error)\n```\nAnthropicToOpenAIChat 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.\n\n```go\nfunc NewOpenAISSEToAnthropicReader(src io.ReadCloser, requestedModel string) io.ReadCloser\n```\nNewOpenAISSEToAnthropicReader translates an OpenAI chat completion SSE stream into the Anthropic Messages SSE event format.\n\n```go\nfunc NewSSEModelRewriteReader(src io.ReadCloser, upstreamModel, alias string) io.ReadCloser\n```\nNewSSEModelRewriteReader 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.\n\nLine-buffered: JSON split across network reads is never touched mid-line, and every other byte (event boundaries, comments, \\[DONE]) passes through verbatim.\n\n```go\nfunc OpenAIResponseToAnthropic(body []byte, requestedModel string) ([]byte, error)\n```\nOpenAIResponseToAnthropic converts a non-streaming OpenAI chat completion JSON document into the Anthropic Messages response format.\n\n```go\nfunc RewriteModel(b []byte, upstream string) ([]byte, error)\n```\n\n```go\nfunc RewriteModelAndThinking(b []byte, upstream string, thinkingBudget int) ([]byte, error)\n```\n\n## Types\n\n```go\ntype AnthropicMessage struct {\n\tRole    string          `json:\"role\"`\n\tContent json.RawMessage `json:\"content\"`\n}\n```\n\n```go\ntype AnthropicMessagesRequest struct {\n\tModel       string             `json:\"model\"`\n\tMessages    []AnthropicMessage `json:\"messages\"`\n\tSystem      json.RawMessage    `json:\"system,omitempty\"`\n\tMaxTokens   int                `json:\"max_tokens,omitempty\"`\n\tTemperature *float64           `json:\"temperature,omitempty\"`\n\tTopP        *float64           `json:\"top_p,omitempty\"`\n\tStream      bool               `json:\"stream,omitempty\"`\n\tTools       []AnthropicTool    `json:\"tools,omitempty\"`\n}\n```\n\n```go\nfunc ParseAnthropicMessages(b []byte) (*AnthropicMessagesRequest, error)\n```\n\n```go\ntype AnthropicTool struct {\n\tName        string          `json:\"name\"`\n\tDescription string          `json:\"description,omitempty\"`\n\tInputSchema json.RawMessage `json:\"input_schema,omitempty\"`\n}\n```\n\n```go\ntype ChatMetadata struct {\n\tModel    string         `json:\"model\"`\n\tStream   bool           `json:\"stream\"`\n\tUser     string         `json:\"user\"`\n\tMetadata map[string]any `json:\"metadata\"`\n}\n```\n\n```go\nfunc ParseChat(b []byte) (ChatMetadata, error)\n```\n\n```go\ntype EndpointMetadata = ChatMetadata\n```\n\n```go\nfunc ParseEndpoint(b []byte) (EndpointMetadata, error)\n```\n\n```go\ntype ThinkingConfig struct {\n\tType         string `json:\"type\"`\n\tBudgetTokens int    `json:\"budget_tokens\"`\n}\n```\n\n","path":"github.com/Rethinger/2papi/internal/protocol","name":"protocol","synopsis":"","isRedistributable":true}
