request

package
v1.261203.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MPL-2.0 Imports: 21 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 AnthropicParamOpt

func AnthropicParamOpt[T comparable](value T) param.Opt[T]

AnthropicParamOpt wraps param.NewOpt for the Anthropic SDK. Kept as a named alias to avoid import collisions when both Anthropic and OpenAI SDK param packages are used in the same file (both export NewOpt/Opt).

func CleanupOpenaiFields

func CleanupOpenaiFields(req *openai.ChatCompletionNewParams)

CleanupOpenaiFields removes temporary fields used during transformation Note: This should be called AFTER vendor transforms have processed x_thinking

func ConvertAnthropicBetaToGoogleRequest

func ConvertAnthropicBetaToGoogleRequest(anthropicReq *anthropic.BetaMessageNewParams, defaultMaxTokens int64) (string, []*genai.Content, *genai.GenerateContentConfig)

ConvertAnthropicBetaToGoogleRequest converts Anthropic beta request to Google format via the shared normalized request view.

func ConvertAnthropicBetaToGoogleToolChoice

func ConvertAnthropicBetaToGoogleToolChoice(tc *anthropic.BetaToolChoiceUnionParam) *genai.ToolConfig

func ConvertAnthropicBetaToGoogleTools

func ConvertAnthropicBetaToGoogleTools(tools []anthropic.BetaToolUnionParam) []*genai.FunctionDeclaration

func ConvertAnthropicBetaToOpenAIRequest

func ConvertAnthropicBetaToOpenAIRequest(anthropicReq *anthropic.BetaMessageNewParams, compatible bool, isStreaming bool, disableStreamUsage bool) (*openai.ChatCompletionNewParams, *protocol.OpenAIConfig)

ConvertAnthropicBetaToOpenAIRequest converts Anthropic beta request to OpenAI format. Returns the OpenAI request and a config object with metadata for provider transforms. The conversion itself is shared with the v1 variant via the normalized request view (see anthropic_view.go).

func ConvertAnthropicBetaToResponsesRequest

func ConvertAnthropicBetaToResponsesRequest(anthropicReq *anthropic.BetaMessageNewParams) *responses.ResponseNewParams

ConvertAnthropicBetaToResponsesRequest converts Anthropic beta request to OpenAI Responses API format The Responses API has a different structure than Chat Completions

func ConvertAnthropicBetaToV1Request added in v1.261001.1

func ConvertAnthropicBetaToV1Request(req *anthropic.BetaMessageNewParams) (*anthropic.MessageNewParams, error)

ConvertAnthropicBetaToV1Request is the provider-edge downgrade: the inverse projection for providers reached over the V1 wire. It is lossless for any request that originated as V1, so it refuses, rather than silently drops, what V1 cannot express: anthropic-beta header values and Beta-only top-level fields.

func ConvertAnthropicBetaToolChoiceToOpenAI

func ConvertAnthropicBetaToolChoiceToOpenAI(tc *anthropic.BetaToolChoiceUnionParam) openai.ChatCompletionToolChoiceOptionUnionParam

ConvertAnthropicBetaToolChoiceToOpenAI converts Anthropic beta tool_choice to OpenAI format

func ConvertAnthropicBetaToolChoiceToResponses

func ConvertAnthropicBetaToolChoiceToResponses(tc *anthropic.BetaToolChoiceUnionParam) responses.ResponseNewParamsToolChoiceUnion

ConvertAnthropicBetaToolChoiceToResponses converts Anthropic beta tool_choice to Responses API format

func ConvertAnthropicBetaToolsToOpenAI

func ConvertAnthropicBetaToolsToOpenAI(tools []anthropic.BetaToolUnionParam) []openai.ChatCompletionToolUnionParam

ConvertAnthropicBetaToolsToOpenAI converts Anthropic beta tools to OpenAI format

func ConvertAnthropicBetaToolsToOpenAIWithTransformedSchema

func ConvertAnthropicBetaToolsToOpenAIWithTransformedSchema(tools []anthropic.BetaToolUnionParam) []openai.ChatCompletionToolUnionParam

ConvertAnthropicBetaToolsToOpenAIWithTransformedSchema is an alias for ConvertAnthropicBetaToolsToOpenAI Schema transformation is handled by provider-specific transforms

func ConvertAnthropicBetaToolsToResponses

func ConvertAnthropicBetaToolsToResponses(tools []anthropic.BetaToolUnionParam) []responses.ToolUnionParam

ConvertAnthropicBetaToolsToResponses converts Anthropic beta tools to Responses API format

func ConvertAnthropicToGoogleRequest

func ConvertAnthropicToGoogleRequest(anthropicReq *anthropic.MessageNewParams, defaultMaxTokens int64) (string, []*genai.Content, *genai.GenerateContentConfig)

ConvertAnthropicToGoogleRequest converts Anthropic request to Google format. The conversion is shared with the Beta variant via the normalized request view (see anthropic_view.go).

func ConvertAnthropicToGoogleToolChoice

func ConvertAnthropicToGoogleToolChoice(tc *anthropic.ToolChoiceUnionParam) *genai.ToolConfig

func ConvertAnthropicToGoogleTools

func ConvertAnthropicToGoogleTools(tools []anthropic.ToolUnionParam) []*genai.FunctionDeclaration

func ConvertAnthropicToOpenAIRequest

func ConvertAnthropicToOpenAIRequest(anthropicReq *anthropic.MessageNewParams, compatible bool, isStreaming bool, disableStreamUsage bool) (*openai.ChatCompletionNewParams, *protocol.OpenAIConfig)

ConvertAnthropicToOpenAIRequest converts Anthropic request to OpenAI format. Returns the OpenAI request and a config object with metadata for provider transforms. The conversion itself is shared with the Beta variant via the normalized request view (see anthropic_view.go).

func ConvertAnthropicToolChoiceToOpenAI

func ConvertAnthropicToolChoiceToOpenAI(tc *anthropic.ToolChoiceUnionParam) openai.ChatCompletionToolChoiceOptionUnionParam

ConvertAnthropicToolChoiceToOpenAI converts Anthropic tool_choice to OpenAI format

func ConvertAnthropicToolsToOpenAI

func ConvertAnthropicToolsToOpenAI(tools []anthropic.ToolUnionParam) []openai.ChatCompletionToolUnionParam

ConvertAnthropicToolsToOpenAI converts Anthropic tools to OpenAI format

func ConvertAnthropicToolsToOpenAIWithTransformedSchema

func ConvertAnthropicToolsToOpenAIWithTransformedSchema(tools []anthropic.ToolUnionParam) []openai.ChatCompletionToolUnionParam

ConvertAnthropicToolsToOpenAIWithTransformedSchema is an alias for ConvertAnthropicToolsToOpenAI Schema transformation is handled by provider-specific transforms

func ConvertAnthropicV1ToBetaRequest added in v0.260514.1

func ConvertAnthropicV1ToBetaRequest(req *anthropic.MessageNewParams) *anthropic.BetaMessageNewParams

ConvertAnthropicV1ToBetaRequest projects an Anthropic v1 MessageNewParams onto the Beta MessageNewParams shape. Beta's wire format is a strict structural superset of v1's (same field names and shapes; Beta only adds optional fields), so a v1 request's own JSON round-trips losslessly into the Beta struct — every block type (text, image, tool_use, tool_result, documents, cache_control, ...) survives without hand-maintained per-type conversion. This previously did a field-by-field Go copy that silently dropped tool_result content and image data; the round-trip has no such gaps and needs no updates when the SDK adds new block types.

This compatibility wrapper keeps the historical nil-on-failure behavior for context-extraction callers. Protocol boundaries that need an actionable error should use ConvertAnthropicV1ToBetaRequestWithError.

func ConvertAnthropicV1ToBetaRequestWithError added in v0.260806.1

func ConvertAnthropicV1ToBetaRequestWithError(req *anthropic.MessageNewParams) (*anthropic.BetaMessageNewParams, error)

ConvertAnthropicV1ToBetaRequestWithError performs the same wire conversion and reports malformed or non-JSON parameter values to the caller.

func ConvertAnthropicV1ToResponsesRequest

func ConvertAnthropicV1ToResponsesRequest(anthropicReq *anthropic.MessageNewParams) *responses.ResponseNewParams

ConvertAnthropicV1ToResponsesRequest converts Anthropic v1 request to OpenAI Responses API format The Responses API has a different structure than Chat Completions

func ConvertAnthropicV1ToolChoiceToResponses

func ConvertAnthropicV1ToolChoiceToResponses(tc *anthropic.ToolChoiceUnionParam) responses.ResponseNewParamsToolChoiceUnion

ConvertAnthropicV1ToolChoiceToResponses converts Anthropic v1 tool_choice to Responses API format

func ConvertAnthropicV1ToolsToResponses

func ConvertAnthropicV1ToolsToResponses(tools []anthropic.ToolUnionParam) []responses.ToolUnionParam

ConvertAnthropicV1ToolsToResponses converts Anthropic v1 tools to Responses API format

func ConvertBetaContentBlocksToString

func ConvertBetaContentBlocksToString(blocks []anthropic.BetaContentBlockParamUnion) string

ConvertBetaContentBlocksToString converts Anthropic beta content blocks to string

func ConvertBetaTextBlocksToString

func ConvertBetaTextBlocksToString(blocks []anthropic.BetaTextBlockParam) string

ConvertBetaTextBlocksToString converts Anthropic beta TextBlockParam array to string

func ConvertChatMessagesToResponsesInput added in v0.260507.1

func ConvertChatMessagesToResponsesInput(messages []openai.ChatCompletionMessageParamUnion) responses.ResponseInputParam

ConvertChatMessagesToResponsesInput converts Chat Completion messages to Responses API input items.

func ConvertChatToOpenAIResponses added in v0.260507.1

func ConvertChatToOpenAIResponses(params *openai.ChatCompletionNewParams, defaultMaxTokens int64) *responses.ResponseNewParams

ConvertChatToOpenAIResponses converts OpenAI Chat Completions params to Responses API format. This enables using Chat Completions format with Responses API providers.

func ConvertChatToolChoiceToResponsesToolChoice added in v0.260507.1

func ConvertChatToolChoiceToResponsesToolChoice(choice *openai.ChatCompletionToolChoiceOptionUnionParam) responses.ResponseNewParamsToolChoiceUnion

ConvertChatToolChoiceToResponsesToolChoice converts Chat Completion tool_choice to Responses API format.

func ConvertChatToolsToResponsesTools added in v0.260507.1

func ConvertChatToolsToResponsesTools(tools []openai.ChatCompletionToolUnionParam) []responses.ToolUnionParam

ConvertChatToolsToResponsesTools converts Chat Completion tools to Responses API tools.

func ConvertContentBlocksToString

func ConvertContentBlocksToString(blocks []anthropic.ContentBlockParamUnion) string

ConvertContentBlocksToString converts Anthropic content blocks to string

func ConvertFunctionCallOutputToChatGPTFormat

func ConvertFunctionCallOutputToChatGPTFormat(output *responses.ResponseInputItemFunctionCallOutputParam) map[string]interface{}

ConvertFunctionCallOutputToChatGPTFormat converts function_call_output items to ChatGPT backend format.

func ConvertFunctionCallToChatGPTFormat

func ConvertFunctionCallToChatGPTFormat(call *responses.ResponseFunctionToolCallParam) map[string]interface{}

ConvertFunctionCallToChatGPTFormat converts function_call items to ChatGPT backend format.

func ConvertGooglePartsToString

func ConvertGooglePartsToString(parts []*genai.Part) string

ConvertGooglePartsToString converts Google parts to a single string

func ConvertGoogleToAnthropicRequest

func ConvertGoogleToAnthropicRequest(model string, contents []*genai.Content, config *genai.GenerateContentConfig) anthropic.MessageNewParams

ConvertGoogleToAnthropicRequest converts Google Content and config to Anthropic format

func ConvertGoogleToOpenAIRequest

func ConvertGoogleToOpenAIRequest(model string, contents []*genai.Content, config *genai.GenerateContentConfig) *openai.ChatCompletionNewParams

ConvertGoogleToOpenAIRequest converts Google Content and config to OpenAI format

func ConvertGoogleToolChoiceToAnthropic

func ConvertGoogleToolChoiceToAnthropic(config *genai.FunctionCallingConfig) anthropic.ToolChoiceUnionParam

func ConvertGoogleToolsToAnthropic

func ConvertGoogleToolsToAnthropic(funcs []*genai.FunctionDeclaration) []anthropic.ToolUnionParam

func ConvertOpenAIResponsesToAnthropicBetaRequest

func ConvertOpenAIResponsesToAnthropicBetaRequest(
	params responses.ResponseNewParams,
	defaultMaxTokens int64,
) *anthropic.BetaMessageNewParams

ConvertOpenAIResponsesToAnthropicBetaRequest converts OpenAI Responses API params to Anthropic Beta Message API format.

Note: The following Responses API fields are not supported in Anthropic's Message API:

  • MaxToolCalls: Anthropic doesn't have an equivalent limit
  • ParallelToolCalls: Anthropic supports parallel tool calls by default
  • Include (web_search sources, code interpreter outputs, etc.): Not supported
  • PreviousResponseID: Requires conversation state management
  • TopLogprobs: Anthropic Message API doesn't support logprobs
  • Reasoning tokens: Special handling required for o1/o3 models

func ConvertOpenAIResponsesToChat

func ConvertOpenAIResponsesToChat(params *responses.ResponseNewParams, defaultMaxTokens int64) *openai.ChatCompletionNewParams

ConvertOpenAIResponsesToChat converts OpenAI Responses API params to Chat Completions format. This is useful when translating between the two API formats.

func ConvertOpenAIToAnthropicRequest

func ConvertOpenAIToAnthropicRequest(req *openai.ChatCompletionNewParams, defaultMaxTokens int64) *anthropic.BetaMessageNewParams

ConvertOpenAIToAnthropicRequest converts OpenAI ChatCompletionNewParams to Anthropic SDK format

func ConvertOpenAIToGoogleRequest

func ConvertOpenAIToGoogleRequest(req *openai.ChatCompletionNewParams, defaultMaxTokens int64) (string, []*genai.Content, *genai.GenerateContentConfig)

ConvertOpenAIToGoogleRequest converts OpenAI ChatCompletionNewParams to Google SDK format

func ConvertRawInputToChatGPTFormat

func ConvertRawInputToChatGPTFormat(raw map[string]interface{}) []interface{}

ConvertRawInputToChatGPTFormat converts raw input items to ChatGPT backend API format.

func ConvertResponseInputToChatGPTFormat

func ConvertResponseInputToChatGPTFormat(inputItems responses.ResponseInputParam) []interface{}

ConvertResponseInputToChatGPTFormat converts ResponseInputParam to ChatGPT backend API format.

func ConvertResponseToolChoiceToChatGPTFormat

func ConvertResponseToolChoiceToChatGPTFormat(toolChoice responses.ResponseNewParamsToolChoiceUnion) interface{}

ConvertResponseToolChoiceToChatGPTFormat converts ToolChoice from Responses API format to ChatGPT backend API format.

func ConvertResponseToolsToChatGPTFormat

func ConvertResponseToolsToChatGPTFormat(tools []responses.ToolUnionParam) []interface{}

ConvertResponseToolsToChatGPTFormat converts Tools from Responses API format to ChatGPT backend API format.

func ConvertResponsesInputToMessages

func ConvertResponsesInputToMessages(items responses.ResponseInputParam) []openai.ChatCompletionMessageParamUnion

ConvertResponsesInputToMessages converts Responses API input items to Chat Completion messages.

The input is first passed through RepairResponsesToolCalls, which guarantees that every function_call group is immediately followed by one function_call_output per call and that no output stands without a call. Chat Completions providers (DeepSeek, OpenAI) require exactly that shape: an assistant message carrying tool_calls must be followed by one tool message per call, and a tool message must answer a preceding tool_calls message. The conversion below therefore only has to preserve order.

func ConvertResponsesToolChoiceToAnthropicBeta

func ConvertResponsesToolChoiceToAnthropicBeta(tc responses.ResponseNewParamsToolChoiceUnion) anthropic.BetaToolChoiceUnionParam

ConvertResponsesToolChoiceToAnthropicBeta converts Responses API tool_choice to Anthropic Beta format

func ConvertResponsesToolChoiceToChat

ConvertResponsesToolChoiceToChat converts Responses API tool choice to Chat Completions format.

func ConvertResponsesToolsToAnthropicBeta

func ConvertResponsesToolsToAnthropicBeta(tools []responses.ToolUnionParam) []anthropic.BetaToolUnionParam

ConvertResponsesToolsToAnthropicBeta converts Responses API tools to Anthropic Beta tools

func ConvertResponsesToolsToChatTools

func ConvertResponsesToolsToChatTools(tools []responses.ToolUnionParam) []openai.ChatCompletionToolUnionParam

ConvertResponsesToolsToChatTools converts Responses API tools to Chat Completions tools.

func ConvertTextBlocksToString

func ConvertTextBlocksToString(blocks []anthropic.TextBlockParam) string

ConvertTextBlocksToString converts Anthropic TextBlockParam array to string

func ExtractInstructions

func ExtractInstructions(raw map[string]interface{}) string

ExtractInstructions extracts system message content as instructions.

func IsThinkingEnabled

func IsThinkingEnabled(anthropicReq *anthropic.MessageNewParams) bool

IsThinkingEnabled checks if thinking mode is enabled in the Anthropic request

func IsThinkingEnabledBeta

func IsThinkingEnabledBeta(anthropicReq *anthropic.BetaMessageNewParams) bool

IsThinkingEnabledBeta checks if thinking mode is enabled in the Anthropic beta request

func NormalizeSchemaTypes added in v0.260507.1

func NormalizeSchemaTypes(schema *genai.Schema)

NormalizeSchemaTypes converts lowercase JSON Schema types to Google's uppercase format This recursively processes all schemas, including nested properties and array items

func OpenAIConfigFromResponses added in v1.261001.1

func OpenAIConfigFromResponses(params *responses.ResponseNewParams) *protocol.OpenAIConfig

OpenAIConfigFromResponses is the OpenAIConfig for a Responses request converted to Chat by ConvertOpenAIResponsesToChat: a reasoning.effort other than "none" marks thinking on at that effort, so the Chat vendor transforms tier it (genericEffortTiers etc.) instead of forwarding it verbatim or dropping it (#1897).

func ParamOpt

func ParamOpt[T comparable](value T) param.Opt[T]

ParamOpt wraps param.NewOpt for the OpenAI SDK. Kept as a named alias to avoid import collisions when both Anthropic and OpenAI SDK param packages are used in the same file (both export NewOpt/Opt).

func ParseImageURLToAnthropicSource added in v0.260531.1

func ParseImageURLToAnthropicSource(url string) (mediaType, data, remoteURL string)

ParseImageURLToAnthropicSource splits a string from OpenAI's image_url.url (used by both Chat Completions and the Responses API) into the bits an Anthropic image source needs.

Returns mediaType and data when the URL is a "data:<mime>;base64,<payload>" data URL. Returns the same URL string back as remoteURL when it's a regular http(s) URL. Exactly one of (mediaType+data) or remoteURL is non-empty for well-formed input.

func RepairResponsesToolCalls added in v0.260924.1

func RepairResponsesToolCalls(items responses.ResponseInputParam) responses.ResponseInputParam

RepairResponsesToolCalls rewrites a Responses API input item list so that the tool-call invariants required by every downstream protocol hold:

  1. every function_call is immediately followed (after its sibling calls from the same assistant turn) by exactly one function_call_output;
  2. no function_call_output stands without a preceding function_call.

The Responses API itself only correlates calls and outputs by call_id: it has no adjacency rule, does not require every call to be answered, and OpenAI even accepts a standalone function_call_output. Codex relies on all three (interrupted turns, automation/heartbeat/cross-thread injections). Chat Completions ("An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'", "Messages with role 'tool' must be a response to a preceding message with 'tool_calls'") and Anthropic ("tool_use ids were found without tool_result blocks immediately after", "unexpected tool_use_id") enforce the stricter shape, so the Responses→Chat and Responses→Anthropic converters both run this first.

Repairs applied, in order of the input:

  • outputs are moved to sit right after the call group that requested them;
  • a call with no output gets a synthesized output carrying missingToolOutputPlaceholder;
  • an output with no call (missing call_id, call trimmed from history, or a duplicate answer) is rewritten as a user message that quotes the output, so its content survives without a dangling tool message;
  • a function_call whose call_id repeats an earlier one is dropped (not observed in practice; guarded because re-emitting it would reach the provider as two tool_calls/tool_use entries sharing one id).

Every other item passes through unchanged, in its original relative order. See .design/protocol-responses.md for the live provider probes.

func RequiresMaxCompletionTokens

func RequiresMaxCompletionTokens(model string) bool

RequiresMaxCompletionTokens checks if the model requires max_completion_tokens instead of max_tokens. Newer OpenAI models (gpt-4o, o1 series, gpt-4.1) use max_completion_tokens.

Types

type ChatGPTBackendRequest

type ChatGPTBackendRequest struct {
	Model         string        `json:"model"`
	Stream        bool          `json:"stream"`
	Instructions  string        `json:"instructions"`
	Input         []interface{} `json:"input,omitempty"`
	Tools         []interface{} `json:"tools,omitempty"`
	ToolChoice    interface{}   `json:"tool_choice,omitempty"`
	Store         bool          `json:"store"`
	Include       []string      `json:"include"`
	MaxTokens     int           `json:"max_tokens,omitempty"`
	MaxCompletion int           `json:"max_completion_tokens,omitempty"`
	Temperature   float64       `json:"temperature,omitempty"`
	TopP          float64       `json:"top_p,omitempty"`
}

ChatGPTBackendRequest represents a request to the ChatGPT backend API.

Jump to

Keyboard shortcuts

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