Documentation
¶
Overview ¶
Package openrouter adapts the OpenRouter HTTP protocol to canonical inference values.
Index ¶
- Constants
- Variables
- func DecodeEmbedding(reader io.Reader) (inference.EmbeddingRequest, error)
- func DecodeImages(reader io.Reader) (inference.ImagesRequest, error)
- func DecodeSpeech(reader io.Reader) (inference.SpeechRequest, error)
- func DecodeTranscriptionForm(form *multipart.Form) (inference.TranscriptionRequest, error)
- func DecodeVideoJob(reader io.Reader) (inference.VideoJobRequest, error)
- func WriteError(w http.ResponseWriter, status int, message string, metadata map[string]any)
- func WriteJSON(w http.ResponseWriter, status int, value any) error
- type Architecture
- type AudioConfig
- type CacheControl
- type ChatRequest
- type ChatResponse
- type Choice
- type CompletionTokenDetails
- type ContentPart
- type DecodedChat
- type Embedding
- type EmbeddingRequest
- type EmbeddingResponse
- type ErrorDetail
- type ErrorResponse
- type File
- type Function
- type FunctionCall
- type GeneratedAudio
- type GeneratedImage
- type ImageDatum
- type ImageURL
- type ImagesRequest
- type ImagesResponse
- type InputAudio
- type JSONSchema
- type LogProb
- type LogProbs
- type MaxPrice
- type Message
- type MessageDelta
- type Model
- type ModelAuthor
- type ModelLineage
- type ModelLinks
- type ModelList
- type ModelOffering
- type OfferingPricing
- type Pricing
- type PromptTokenDetails
- type ProviderPreferences
- type Reasoning
- type RerankDecoding
- type RerankRequest
- type RerankResponse
- type RerankResult
- type RerankUsage
- type ResponseFormat
- type ResponseMessage
- type SpeechRequest
- type StreamChoice
- type StreamChunk
- type StreamErrorChunk
- type StreamOptions
- type Tool
- type ToolCall
- type TopLogProb
- type TopProvider
- type TranscriptionResponse
- type Usage
- type VideoJob
- type VideoJobError
- type VideoJobList
- type VideoJobRequest
- type VideoURL
Constants ¶
const ( SortPrice = "price" SortLatency = "latency" SortThroughput = "throughput" SortSpread = "spread" )
Sort values the OpenRouter provider-routing policy documents, plus the Starport spread extension that balances traffic inside a ranking band.
Variables ¶
var ( // ErrUnenforcedPlugin reports a plugin identifier this gateway does not // run. It is a refusal rather than a report, because a plugin changes // what the model reads: serving the request without it answers a // different question than the caller asked. ErrUnenforcedPlugin = errors.New("plugin is not enforced by this gateway") // ErrUnknownParserEngine reports a parser engine outside the vocabulary // this gateway runs. ErrUnknownParserEngine = errors.New("file-parser engine is not served by this gateway") // ErrDuplicateFileParser reports a request that configures the parser // twice. Two entries can name two engines, and picking either one // silently would extract the document a way the caller did not choose. ErrDuplicateFileParser = errors.New("plugins names file-parser more than once") )
var ErrRerankDocumentUnsupported = errors.New("openrouter rerank document is not text")
ErrRerankDocumentUnsupported reports a structured document this gateway cannot rank. A rerank provider scores text. An image document reaches the wire as a picture the transport has no field for, and ranking its caption would answer a question the caller did not ask.
Functions ¶
func DecodeEmbedding ¶
func DecodeEmbedding(reader io.Reader) (inference.EmbeddingRequest, error)
DecodeEmbedding decodes one strict OpenRouter embeddings request.
func DecodeImages ¶ added in v1.1.0
func DecodeImages(reader io.Reader) (inference.ImagesRequest, error)
DecodeImages decodes one strict OpenRouter image request.
func DecodeSpeech ¶ added in v1.1.0
func DecodeSpeech(reader io.Reader) (inference.SpeechRequest, error)
DecodeSpeech decodes one strict OpenRouter text-to-speech request.
func DecodeTranscriptionForm ¶ added in v1.1.0
func DecodeTranscriptionForm(form *multipart.Form) (inference.TranscriptionRequest, error)
DecodeTranscriptionForm decodes one OpenRouter speech-to-text request from multipart form data.
func DecodeVideoJob ¶ added in v1.1.0
func DecodeVideoJob(reader io.Reader) (inference.VideoJobRequest, error)
DecodeVideoJob decodes one strict OpenRouter video generation request.
func WriteError ¶
WriteError writes one OpenRouter error response.
Types ¶
type Architecture ¶
type Architecture struct {
InputModalities []string `json:"input_modalities"`
OutputModalities []string `json:"output_modalities"`
Tokenizer string `json:"tokenizer"`
InstructType *string `json:"instruct_type"`
}
Architecture describes one OpenRouter model architecture.
type AudioConfig ¶ added in v1.1.0
type AudioConfig struct {
Voice string `json:"voice,omitempty"`
Format string `json:"format,omitempty"`
}
AudioConfig selects the voice and container for a spoken answer. A provider that serves audio requires both, and neither carries a gateway default.
type CacheControl ¶
type CacheControl struct {
Type string `json:"type"`
}
CacheControl marks an ephemeral prompt-cache breakpoint.
type ChatRequest ¶
type ChatRequest struct {
Model string `json:"model,omitempty"`
Models []string `json:"models,omitempty"`
Messages []Message `json:"messages"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
TopK *int `json:"top_k,omitempty"`
N *int `json:"n,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamOptions *StreamOptions `json:"stream_options,omitempty"`
Stop json.RawMessage `json:"stop,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"`
PresencePenalty *float32 `json:"presence_penalty,omitempty"`
FrequencyPenalty *float32 `json:"frequency_penalty,omitempty"`
RepetitionPenalty *float32 `json:"repetition_penalty,omitempty"`
MinP *float32 `json:"min_p,omitempty"`
TopA *float32 `json:"top_a,omitempty"`
LogitBias map[string]int `json:"logit_bias,omitempty"`
LogProbs *bool `json:"logprobs,omitempty"`
TopLogProbs *int `json:"top_logprobs,omitempty"`
User string `json:"user,omitempty"`
Seed *int `json:"seed,omitempty"`
Tools []Tool `json:"tools,omitempty"`
ToolChoice json.RawMessage `json:"tool_choice,omitempty"`
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"`
ResponseFormat *ResponseFormat `json:"response_format,omitempty"`
Reasoning *Reasoning `json:"reasoning,omitempty"`
ReasoningEffort string `json:"reasoning_effort,omitempty"`
Provider *ProviderPreferences `json:"provider,omitempty"`
Preset string `json:"preset,omitempty"`
Route string `json:"route,omitempty"`
Transforms []string `json:"transforms,omitempty"`
Plugins []json.RawMessage `json:"plugins,omitempty"`
Usage json.RawMessage `json:"usage,omitempty"`
Debug json.RawMessage `json:"debug,omitempty"`
// Modalities names what the caller will accept back. Absent means text,
// which is what every model served before this field existed.
Modalities []string `json:"modalities,omitempty"`
// Audio configures the spoken answer that Modalities asks for.
Audio *AudioConfig `json:"audio,omitempty"`
}
ChatRequest is the OpenRouter chat-completions wire request.
type ChatResponse ¶
type ChatResponse struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Choices []Choice `json:"choices"`
Usage Usage `json:"usage"`
SystemFingerprint *string `json:"system_fingerprint"`
}
ChatResponse is the OpenRouter chat-completions wire response.
func EncodeChat ¶
func EncodeChat(response inference.ChatResponse) ChatResponse
EncodeChat converts one canonical chat result to OpenRouter wire values.
type Choice ¶
type Choice struct {
Index int `json:"index"`
Message ResponseMessage `json:"message"`
FinishReason string `json:"finish_reason"`
NativeFinishReason string `json:"native_finish_reason,omitempty"`
LogProbs *LogProbs `json:"logprobs,omitempty"`
}
Choice is one OpenRouter chat-completions result.
type CompletionTokenDetails ¶
type CompletionTokenDetails struct {
ReasoningTokens int `json:"reasoning_tokens"`
// AudioTokens counts the audio share of CompletionTokens.
AudioTokens int `json:"audio_tokens,omitempty"`
}
CompletionTokenDetails contains reasoning-token accounting.
type ContentPart ¶
type ContentPart struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
ImageURL *ImageURL `json:"image_url,omitempty"`
InputAudio *InputAudio `json:"input_audio,omitempty"`
File *File `json:"file,omitempty"`
VideoURL *VideoURL `json:"video_url,omitempty"`
CacheControl *CacheControl `json:"cache_control,omitempty"`
}
ContentPart is one OpenRouter multipart message input.
type DecodedChat ¶
type DecodedChat struct {
Inference inference.ChatRequest
Route string
Provider *ProviderPreferences
// Preset names a stored preset the request selects by body field.
Preset string
// UnenforcedProviderFields names documented OpenRouter fields this request
// used that Starport accepts but cannot yet enforce, in sorted order. It
// covers both provider-routing preferences and top-level gateway fields,
// because the caller reads one list and only cares which promises were not
// kept.
UnenforcedProviderFields []string
}
DecodedChat contains canonical inference and OpenRouter routing policy.
func DecodeChat ¶
func DecodeChat(reader io.Reader) (DecodedChat, error)
DecodeChat decodes one strict OpenRouter request into canonical inference.
type Embedding ¶
type Embedding struct {
Object string `json:"object"`
Index int `json:"index"`
Embedding []float32 `json:"embedding"`
}
Embedding is one OpenRouter embedding vector.
type EmbeddingRequest ¶
type EmbeddingRequest struct {
Model string `json:"model"`
Input json.RawMessage `json:"input"`
EncodingFormat string `json:"encoding_format,omitempty"`
Dimensions *int `json:"dimensions,omitempty"`
User string `json:"user,omitempty"`
}
EmbeddingRequest is the OpenRouter embeddings wire request.
type EmbeddingResponse ¶
type EmbeddingResponse struct {
Object string `json:"object"`
Data []Embedding `json:"data"`
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Usage Usage `json:"usage"`
}
EmbeddingResponse is the OpenRouter embeddings wire response.
func EncodeEmbedding ¶
func EncodeEmbedding(response inference.EmbeddingResponse) EmbeddingResponse
EncodeEmbedding converts one canonical embedding result to OpenRouter wire values.
type ErrorDetail ¶
type ErrorDetail struct {
Code int `json:"code"`
Message string `json:"message"`
Metadata map[string]any `json:"metadata,omitempty"`
}
ErrorDetail is one OpenRouter API error.
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorDetail `json:"error"`
}
ErrorResponse is the OpenRouter error envelope.
type File ¶ added in v1.1.0
type File struct {
Filename string `json:"filename,omitempty"`
FileData string `json:"file_data,omitempty"`
FileID string `json:"file_id,omitempty"`
}
File is a document input. FileData holds a data URL, and FileID names a document this gateway stores for the requesting account.
type Function ¶
type Function struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Parameters json.RawMessage `json:"parameters"`
}
Function defines an OpenRouter function tool.
type FunctionCall ¶
FunctionCall is one requested function invocation.
type GeneratedAudio ¶ added in v1.1.0
type GeneratedAudio struct {
Data string `json:"data,omitempty"`
Transcript string `json:"transcript,omitempty"`
Format string `json:"format,omitempty"`
}
GeneratedAudio is a spoken answer. Data is raw base64 with no data URL prefix, matching the audio input shape on the same wire.
type GeneratedImage ¶ added in v1.1.0
type GeneratedImage struct {
Type string `json:"type"`
ImageURL *ImageURL `json:"image_url,omitempty"`
Index int `json:"index,omitempty"`
}
GeneratedImage is one picture a model produced. It repeats the input part shape, so a caller sends back what it received without translating.
type ImageDatum ¶ added in v1.1.0
type ImageDatum struct {
B64JSON string `json:"b64_json,omitempty"`
URL string `json:"url,omitempty"`
RevisedPrompt string `json:"revised_prompt,omitempty"`
}
ImageDatum is one generated image, inline or by reference.
type ImagesRequest ¶ added in v1.1.0
type ImagesRequest struct {
Model string `json:"model"`
Prompt string `json:"prompt"`
N int `json:"n,omitempty"`
Size string `json:"size,omitempty"`
Quality string `json:"quality,omitempty"`
Style string `json:"style,omitempty"`
ResponseFormat string `json:"response_format,omitempty"`
User string `json:"user,omitempty"`
}
ImagesRequest is the OpenRouter image wire request.
type ImagesResponse ¶ added in v1.1.0
type ImagesResponse struct {
Created int64 `json:"created"`
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Data []ImageDatum `json:"data"`
Usage *Usage `json:"usage,omitempty"`
}
ImagesResponse is the OpenRouter image wire response.
func EncodeImages ¶ added in v1.1.0
func EncodeImages(response inference.ImagesResponse) ImagesResponse
EncodeImages converts one canonical image result to OpenRouter wire values.
type InputAudio ¶ added in v1.1.0
InputAudio is an audio input. Data is raw base64 with no data URL prefix, which is why Format names the container beside it.
type JSONSchema ¶
type JSONSchema struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Schema json.RawMessage `json:"schema"`
Strict bool `json:"strict,omitempty"`
}
JSONSchema describes one structured output.
type LogProb ¶
type LogProb struct {
Token string `json:"token"`
LogProb float64 `json:"logprob"`
Bytes []int `json:"bytes,omitempty"`
TopLogProbs []TopLogProb `json:"top_logprobs"`
}
LogProb is one output-token probability.
type LogProbs ¶
type LogProbs struct {
Content []LogProb `json:"content"`
}
LogProbs contains output-token log probabilities.
type MaxPrice ¶ added in v1.1.0
MaxPrice is the OpenRouter per-request price ceiling in USD per million tokens. OpenRouter accepts each value as a JSON number or a numeric string.
func (*MaxPrice) UnmarshalJSON ¶ added in v1.1.0
UnmarshalJSON accepts the documented max_price object with numeric or quoted-numeric values and rejects unknown keys.
type Message ¶
type Message struct {
Role string `json:"role"`
Content json.RawMessage `json:"content,omitempty"`
Reasoning string `json:"reasoning,omitempty"`
Name string `json:"name,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
Message is one OpenRouter chat message.
type MessageDelta ¶
type MessageDelta struct {
Role string `json:"role,omitempty"`
Content string `json:"content,omitempty"`
Reasoning string `json:"reasoning,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
// Images arrive whole in one delta, because a provider sends a finished
// picture rather than a growing one.
Images []GeneratedImage `json:"images,omitempty"`
// Audio arrives in pieces. OpenRouter serves a spoken answer through
// streaming alone, so this field is the only place it appears.
Audio *GeneratedAudio `json:"audio,omitempty"`
}
MessageDelta is one streamed OpenRouter message update.
type Model ¶
type Model struct {
ID string `json:"id"`
CanonicalSlug string `json:"canonical_slug,omitempty"`
Name string `json:"name"`
Created int64 `json:"created"`
Description string `json:"description,omitempty"`
ContextLength int `json:"context_length"`
Architecture *Architecture `json:"architecture,omitempty"`
Pricing *Pricing `json:"pricing,omitempty"`
TopProvider *TopProvider `json:"top_provider,omitempty"`
SupportedParameters []string `json:"supported_parameters"`
// Catalog facts beyond the OpenRouter baseline surface
Authors []ModelAuthor `json:"authors,omitempty"`
Tags []string `json:"tags,omitempty"`
Lineage *ModelLineage `json:"lineage,omitempty"`
KnowledgeCutoff string `json:"knowledge_cutoff,omitempty"`
OpenWeights *bool `json:"open_weights,omitempty"`
Offerings []ModelOffering `json:"offerings,omitempty"`
}
Model is one OpenRouter model resource.
type ModelAuthor ¶ added in v1.1.0
ModelAuthor names one catalog author of a model.
type ModelLineage ¶ added in v1.1.0
type ModelLineage struct {
Family string `json:"family,omitempty"`
Root string `json:"root,omitempty"`
Parent string `json:"parent,omitempty"`
}
ModelLineage describes canonical model-family relationships.
type ModelLinks ¶
type ModelLinks struct {
Next *string `json:"next"`
}
ModelLinks contains OpenRouter model-list pagination links.
type ModelList ¶
type ModelList struct {
Data []Model `json:"data"`
TotalCount int `json:"total_count"`
Links ModelLinks `json:"links"`
}
ModelList is the OpenRouter model-list response.
type ModelOffering ¶ added in v1.1.0
type ModelOffering struct {
Provider string `json:"provider"`
ProviderName string `json:"provider_name,omitempty"`
ProviderModelID string `json:"provider_model_id"`
ContextLength *int `json:"context_length,omitempty"`
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"`
Availability string `json:"availability,omitempty"`
Lifecycle string `json:"lifecycle,omitempty"`
Pricing *OfferingPricing `json:"pricing,omitempty"`
// MaxDocuments is the longest document list this offering ranks in one
// rerank request. A caller that sends more gets a refusal.
MaxDocuments *int `json:"max_documents,omitempty"`
// Operations names what this offering serves. A caller reads it to learn
// which route answers for the model, because a model that reads documents
// and a model that answers chat reach different paths.
Operations []string `json:"operations,omitempty"`
}
ModelOffering is one provider's routable offering of a model.
type OfferingPricing ¶ added in v1.1.0
type OfferingPricing struct {
Prompt string `json:"prompt,omitempty"`
Completion string `json:"completion,omitempty"`
Reasoning string `json:"reasoning,omitempty"`
CacheRead string `json:"cache_read,omitempty"`
CacheWrite string `json:"cache_write,omitempty"`
// Audio tokens bill at their own rate wherever a provider meters them.
AudioInput string `json:"audio_input,omitempty"`
AudioOutput string `json:"audio_output,omitempty"`
// A page is the unit document recognition bills in. No token price
// converts into it.
PageInput string `json:"page_input,omitempty"`
// A search unit is the unit reranking bills in on the providers that
// meter it: one query against a bounded document count. Such an offering
// may publish no token price at all.
SearchUnit string `json:"search_unit,omitempty"`
Currency string `json:"currency,omitempty"`
}
OfferingPricing carries the published prices of one offering. The token dimensions price one token each. PageInput prices one document page.
type PromptTokenDetails ¶ added in v1.1.0
type PromptTokenDetails struct {
AudioTokens int `json:"audio_tokens,omitempty"`
}
PromptTokenDetails breaks the prompt total down. A caller that asked for a spoken turn reconciles its bill from the audio share, because a provider charges audio at a rate the plain input rate does not describe.
type ProviderPreferences ¶
type ProviderPreferences struct {
Order []string `json:"order,omitempty"`
Only []string `json:"only,omitempty"`
Ignore []string `json:"ignore,omitempty"`
AllowFallbacks *bool `json:"allow_fallbacks,omitempty"`
RequireParameters *bool `json:"require_parameters,omitempty"`
DataCollection string `json:"data_collection,omitempty"`
ZDR *bool `json:"zdr,omitempty"`
Quantizations []string `json:"quantizations,omitempty"`
Experimental json.RawMessage `json:"experimental,omitempty"`
Sort string `json:"sort,omitempty"`
MaxPrice *MaxPrice `json:"max_price,omitempty"`
}
ProviderPreferences is the OpenRouter provider-routing policy.
type Reasoning ¶
type Reasoning struct {
Effort string `json:"effort,omitempty"`
MaxTokens *int `json:"max_tokens,omitempty"`
Exclude bool `json:"exclude,omitempty"`
}
Reasoning configures OpenRouter reasoning behavior.
type RerankDecoding ¶ added in v1.1.0
type RerankDecoding struct {
Request inference.RerankRequest
// UnenforcedProviderFields names documented provider fields this request
// used that Starport accepts without enforcing. Accepting a documented
// field is the contract. Staying quiet about an unkept one is not.
UnenforcedProviderFields []string
}
RerankDecoding is one decoded OpenRouter rerank request with the unkept promises the drop-in contract requires the answer to report.
func DecodeRerank ¶ added in v1.1.0
func DecodeRerank(reader io.Reader) (RerankDecoding, error)
DecodeRerank decodes one strict OpenRouter rerank request.
type RerankRequest ¶ added in v1.1.0
type RerankRequest struct {
Model string `json:"model"`
Query string `json:"query"`
Documents []json.RawMessage `json:"documents"`
TopN *int `json:"top_n,omitempty"`
// MaxTokensPerDoc caps how much of each document the provider reads.
MaxTokensPerDoc *int `json:"max_tokens_per_doc,omitempty"`
// Provider carries the same preference block every other OpenRouter route
// accepts, so one validator covers all of them.
Provider *ProviderPreferences `json:"provider,omitempty"`
}
RerankRequest is the OpenRouter rerank wire request.
type RerankResponse ¶ added in v1.1.0
type RerankResponse struct {
ID string `json:"id,omitempty"`
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Results []RerankResult `json:"results"`
Usage RerankUsage `json:"usage"`
}
RerankResponse is the OpenRouter rerank wire response.
func EncodeRerank ¶ added in v1.1.0
func EncodeRerank( response inference.RerankResponse, request inference.RerankRequest, provider string, costUSD *float64, ) (RerankResponse, error)
EncodeRerank writes one canonical rerank answer in the OpenRouter shape. The schema requires the document on every result, so the request is not optional here the way it is on the /v1 route.
The cost comes from the gateway rather than from the provider. A rerank provider reports the units it billed and no money at all, so the dollar figure is the gateway's own accounting and the caller gets it only when the catalog priced the turn.
type RerankResult ¶ added in v1.1.0
type RerankResult struct {
Index int `json:"index"`
RelevanceScore float64 `json:"relevance_score"`
Document string `json:"document"`
}
RerankResult is one scored document. OpenRouter marks the document required, so this codec always echoes it.
type RerankUsage ¶ added in v1.1.0
type RerankUsage struct {
SearchUnits int `json:"search_units,omitempty"`
TotalTokens int `json:"total_tokens,omitempty"`
// Cost is what the gateway charged, in US dollars. OpenRouter states it on
// every rerank answer. A turn the catalog could not price omits it rather
// than reporting zero, because zero is a price a caller would believe.
Cost *float64 `json:"cost,omitempty"`
}
RerankUsage reports what a rerank turn consumed. Providers split on the unit: one bills a search unit and another bills tokens, so the answer states whichever one the provider reported and omits the other.
type ResponseFormat ¶
type ResponseFormat struct {
Type string `json:"type"`
JSONSchema *JSONSchema `json:"json_schema,omitempty"`
}
ResponseFormat is the OpenRouter response-format contract.
type ResponseMessage ¶
type ResponseMessage struct {
Role string `json:"role"`
Content string `json:"content"`
Reasoning string `json:"reasoning,omitempty"`
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
// Images carries generated pictures, in the shape OpenRouter documents.
Images []GeneratedImage `json:"images,omitempty"`
// Audio carries a spoken answer. Content keeps the transcript beside it
// rather than going empty, because a caller that cannot play audio still
// has the answer.
Audio *GeneratedAudio `json:"audio,omitempty"`
}
ResponseMessage is one OpenRouter assistant message.
type SpeechRequest ¶ added in v1.1.0
type SpeechRequest struct {
Model string `json:"model"`
Input string `json:"input"`
Voice string `json:"voice,omitempty"`
ResponseFormat string `json:"response_format,omitempty"`
Speed *float64 `json:"speed,omitempty"`
}
SpeechRequest is the OpenRouter text-to-speech wire request.
type StreamChoice ¶
type StreamChoice struct {
Index int `json:"index"`
Delta MessageDelta `json:"delta"`
FinishReason *string `json:"finish_reason"`
LogProbs *LogProbs `json:"logprobs,omitempty"`
}
StreamChoice is one streamed OpenRouter choice.
type StreamChunk ¶
type StreamChunk struct {
ID string `json:"id"`
Object string `json:"object"`
Created int64 `json:"created"`
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Choices []StreamChoice `json:"choices"`
Usage *Usage `json:"usage,omitempty"`
SystemFingerprint *string `json:"system_fingerprint"`
}
StreamChunk is one OpenRouter SSE data value.
func EncodeStream ¶
func EncodeStream(event inference.StreamEvent) StreamChunk
EncodeStream converts one canonical stream event to an OpenRouter chunk.
type StreamErrorChunk ¶
type StreamErrorChunk struct {
ID string `json:"id,omitempty"`
Object string `json:"object"`
Created int64 `json:"created,omitempty"`
Model string `json:"model,omitempty"`
Error ErrorDetail `json:"error"`
Choices []StreamChoice `json:"choices"`
}
StreamErrorChunk is the OpenRouter mid-stream error contract.
func EncodeStreamError ¶
func EncodeStreamError(event inference.StreamEvent, code int, message string, metadata map[string]any) StreamErrorChunk
EncodeStreamError creates an OpenRouter mid-stream error chunk.
type StreamOptions ¶
type StreamOptions struct {
IncludeUsage bool `json:"include_usage,omitempty"`
}
StreamOptions controls OpenRouter stream usage events.
type ToolCall ¶
type ToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
Function FunctionCall `json:"function"`
}
ToolCall is an OpenRouter function call.
type TopLogProb ¶
type TopLogProb struct {
Token string `json:"token"`
LogProb float64 `json:"logprob"`
Bytes []int `json:"bytes,omitempty"`
}
TopLogProb is one alternate output token.
type TopProvider ¶
type TopProvider struct {
ContextLength int `json:"context_length"`
MaxCompletionTokens int `json:"max_completion_tokens"`
}
TopProvider contains representative provider limits.
type TranscriptionResponse ¶ added in v1.1.0
type TranscriptionResponse struct {
Text string `json:"text"`
Model string `json:"model,omitempty"`
Provider string `json:"provider,omitempty"`
Language string `json:"language,omitempty"`
Duration float64 `json:"duration,omitempty"`
}
TranscriptionResponse is the OpenRouter speech-to-text wire response.
func EncodeTranscription ¶ added in v1.1.0
func EncodeTranscription(response inference.TranscriptionResponse) TranscriptionResponse
EncodeTranscription converts one canonical transcript to OpenRouter wire values.
type Usage ¶
type Usage struct {
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
TotalTokens int `json:"total_tokens"`
CompletionTokenDetails *CompletionTokenDetails `json:"completion_tokens_details,omitempty"`
PromptTokenDetails *PromptTokenDetails `json:"prompt_tokens_details,omitempty"`
}
Usage is OpenRouter token accounting.
type VideoJob ¶ added in v1.1.0
type VideoJob struct {
ID string `json:"id"`
Model string `json:"model"`
Provider string `json:"provider,omitempty"`
Status string `json:"status"`
CreatedAt int64 `json:"created_at"`
CompletedAt int64 `json:"completed_at,omitempty"`
ExpiresAt int64 `json:"expires_at,omitempty"`
Error *VideoJobError `json:"error,omitempty"`
}
VideoJob is the OpenRouter video wire object.
func EncodeVideoJob ¶ added in v1.1.0
EncodeVideoJob converts one canonical job to OpenRouter wire values.
type VideoJobError ¶ added in v1.1.0
type VideoJobError struct {
Message string `json:"message"`
}
VideoJobError states why a failed job produced no video.
type VideoJobList ¶ added in v1.1.0
type VideoJobList struct {
Data []VideoJob `json:"data"`
}
VideoJobList is the OpenRouter listing of one caller's video jobs.
func EncodeVideoJobs ¶ added in v1.1.0
func EncodeVideoJobs(records []inference.VideoJob) VideoJobList
EncodeVideoJobs converts one listing to OpenRouter wire values.
type VideoJobRequest ¶ added in v1.1.0
type VideoJobRequest struct {
Model string `json:"model"`
Prompt string `json:"prompt"`
NegativePrompt string `json:"negative_prompt,omitempty"`
Size string `json:"size,omitempty"`
Seconds string `json:"seconds,omitempty"`
Seed *int64 `json:"seed,omitempty"`
}
VideoJobRequest is the OpenRouter video wire request.