openrouterwire

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package openrouterwire provides shared extension keys and helpers for OpenRouter-specific data that flows from frontend decoders through lipapi.Call.Extensions to backend adapters. It lives at the adapter edge; core packages must not import it.

Index

Constants

View Source
const (
	ExtProvider            = "openrouter.provider"
	ExtModels              = "openrouter.models"
	ExtRoute               = "openrouter.route"
	ExtPlugins             = "openrouter.plugins"
	ExtPrediction          = "openrouter.prediction"
	ExtDebug               = "openrouter.debug"
	ExtServiceTier         = "openrouter.service_tier"
	ExtSessionID           = "openrouter.session_id"
	ExtStopServerToolsWhen = "openrouter.stop_server_tools_when"
	ExtTrace               = "openrouter.trace"
	ExtInclude             = "openrouter.include"
	ExtUser                = "openrouter.user"
	ExtHTTPReferer         = "openrouter.http_referer"
	ExtTitle               = "openrouter.title"
	ExtCategories          = "openrouter.categories"
	ExtMetadataHeader      = "openrouter.metadata_header"
	ExtResponseFormat      = "openrouter.response_format"
	ExtReasoning           = "openrouter.reasoning"
	ExtUpstreamFlavor      = "openrouter.upstream_flavor"
)

Extension keys stored in lipapi.Call.Extensions by frontend decoders.

View Source
const (
	FlavorChat      = "chat"
	FlavorResponses = "responses"
)

Upstream flavors for the backend adapter to select the correct endpoint.

View Source
const (
	// MaxExtraBodyFields bounds provider-specific passthrough fields captured from one request body.
	MaxExtraBodyFields = 32
	// MaxExtraBodyFieldNameBytes bounds one provider-specific passthrough field name.
	MaxExtraBodyFieldNameBytes = 64
	// MaxExtraBodyFieldValueBytes bounds one provider-specific passthrough field value.
	MaxExtraBodyFieldValueBytes = 16 << 10
)
View Source
const ExtraBodyExtPrefix = "nvidia.extra_body."

ExtraBodyExtPrefix is the extension key prefix used by OpenAI-compatible frontend adapters to pass NVIDIA-specific extra body fields through the canonical call.

Variables

This section is empty.

Functions

func CaptureBodyFields

func CaptureBodyFields(body map[string]json.RawMessage, ext map[string]json.RawMessage)

CaptureBodyFields reads OpenRouter-specific top-level fields from a decoded JSON body and stores them as json.RawMessage entries in extensions. Existing keys are overwritten.

func CaptureExtraBodyFields

func CaptureExtraBodyFields(body map[string]json.RawMessage, ext map[string]json.RawMessage, knownKeys map[string]bool)

CaptureExtraBodyFields stores unrecognized top-level JSON body fields as extensions under the ExtraBodyExtPrefix prefix. Fields present in knownKeys or in the OpenRouter bodyFieldPassthrough table are skipped. Null and empty values are skipped.

func CaptureHeaders

func CaptureHeaders(h http.Header, ext map[string]json.RawMessage)

CaptureHeaders reads OpenRouter-specific HTTP headers and stores them as quoted JSON strings in extensions. Invalid or over-bound HTTP-Referer / title values are omitted (not rejected).

func ExtraBodyValueWithinBounds

func ExtraBodyValueWithinBounds(raw json.RawMessage) bool

ExtraBodyValueWithinBounds reports whether raw is non-empty, non-null, and bounded for passthrough.

func GetRaw

func GetRaw(ext map[string]json.RawMessage, key string) json.RawMessage

GetRaw returns the raw JSON value from ext[key] or nil.

func GetString

func GetString(ext map[string]json.RawMessage, key string) string

GetString reads a JSON-quoted string from ext[key] or returns "".

func ValidExtraBodyFieldName

func ValidExtraBodyFieldName(name string) bool

ValidExtraBodyFieldName reports whether name is safe to pass to SDK JSON-set helpers as one top-level key.

Types

This section is empty.

Jump to

Keyboard shortcuts

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