openai

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package openai adapts the OpenAI HTTP protocol to canonical inference values.

Index

Constants

View Source
const (
	// StoredFileObject is the literal every file object carries.
	StoredFileObject = "file"
	// ListObject is the literal every list envelope carries. A stored file
	// page, an embedding set, a video job page, and a rerank answer all state it.
	ListObject = "list"
)
View Source
const (
	// StoredFileStatusUploaded names a file whose bytes have not committed.
	StoredFileStatusUploaded = "uploaded"
	// StoredFileStatusProcessed names a readable file.
	StoredFileStatusProcessed = "processed"
)

The status field. Upstream marks it deprecated and Starport still serves it, because a strict SDK decode reads it and Starport holds a real two-state record behind it. A record whose bytes have not finished landing reads as uploaded, and a readable one reads as processed.

View Source
const (
	// BatchCompletionWindow is the one window OpenAI publishes. A gateway a
	// developer runs starts the work at once, so the window is a promise the
	// gateway keeps trivially, and any other value is a request it cannot
	// honor the way the caller means it.
	BatchCompletionWindow = "24h"
)

Variables

This section is empty.

Functions

func BatchEndpoints added in v1.2.0

func BatchEndpoints() []string

BatchEndpoints lists the operation paths a batch may call, which are the request-shaped operations this gateway serves: chat, embeddings, and responses. A media operation stays online, because its result is bytes rather than a JSON body a result line can carry.

func DecodeBatchCreate added in v1.2.0

func DecodeBatchCreate(reader io.Reader) (inference.BatchCreateRequest, error)

DecodeBatchCreate decodes one strict OpenAI batch creation request.

func DecodeBatchLine added in v1.2.0

func DecodeBatchLine(line []byte, endpoint string) (inference.BatchLine, error)

DecodeBatchLine decodes one strict input line and checks it against the batch's endpoint. A line that names another endpoint fails here, before any provider call, because one batch serves one operation.

func DecodeChat

func DecodeChat(reader io.Reader) (inference.ChatRequest, error)

DecodeChat decodes one strict OpenAI request into canonical inference.

func DecodeEmbedding

func DecodeEmbedding(reader io.Reader) (inference.EmbeddingRequest, error)

DecodeEmbedding decodes one strict OpenAI embeddings request.

func DecodeImages added in v1.1.0

func DecodeImages(reader io.Reader) (inference.ImagesRequest, error)

DecodeImages decodes one strict OpenAI image generation request.

func DecodeImagesForm added in v1.1.0

func DecodeImagesForm(form *multipart.Form) (inference.ImagesRequest, error)

DecodeImagesForm decodes one OpenAI image edit request from multipart form data.

func DecodeModerations added in v1.2.0

func DecodeModerations(reader io.Reader) (inference.ModerationRequest, error)

DecodeModerations decodes one strict moderation request. An unknown field fails the same way it fails on the chat route.

func DecodeResponses added in v1.2.0

func DecodeResponses(reader io.Reader) (inference.ChatRequest, error)

DecodeResponses decodes one strict Responses request into the canonical chat request. A stored-state field returns an UnsupportedError that names it.

func DecodeSpeech added in v1.1.0

func DecodeSpeech(reader io.Reader) (inference.SpeechRequest, error)

DecodeSpeech decodes one strict OpenAI text-to-speech request.

func DecodeTranscriptionForm added in v1.1.0

func DecodeTranscriptionForm(form *multipart.Form, translate bool) (inference.TranscriptionRequest, error)

DecodeTranscriptionForm decodes one OpenAI speech-to-text request from multipart form data. translate states whether the caller reached the translation path.

func DecodeVideoJob added in v1.1.0

func DecodeVideoJob(reader io.Reader) (inference.VideoJobRequest, error)

DecodeVideoJob decodes one strict OpenAI video generation request.

func EncodeBatchOutputLine added in v1.2.0

func EncodeBatchOutputLine(result inference.BatchLineResult) ([]byte, error)

EncodeBatchOutputLine converts one line result to its wire line. The same shape serves the output file and the error file: which file the line landed in already says whether it failed, and the status code repeats it.

func WriteError

func WriteError(w http.ResponseWriter, status int, errorType, message string, param *string)

WriteError writes one OpenAI error response.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, value any) error

WriteJSON writes one OpenAI JSON value.

Types

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 Batch added in v1.2.0

type Batch struct {
	ID               string             `json:"id"`
	Object           string             `json:"object"`
	Endpoint         string             `json:"endpoint"`
	InputFileID      string             `json:"input_file_id"`
	CompletionWindow string             `json:"completion_window"`
	Status           string             `json:"status"`
	OutputFileID     string             `json:"output_file_id,omitempty"`
	ErrorFileID      string             `json:"error_file_id,omitempty"`
	CreatedAt        int64              `json:"created_at"`
	CompletedAt      int64              `json:"completed_at,omitempty"`
	FailedAt         int64              `json:"failed_at,omitempty"`
	CancelledAt      int64              `json:"cancelled_at,omitempty"`
	RequestCounts    BatchRequestCounts `json:"request_counts"`
	Errors           *BatchErrors       `json:"errors,omitempty"`
}

Batch is the OpenAI batch wire object.

func EncodeBatch added in v1.2.0

func EncodeBatch(batch inference.Batch) Batch

EncodeBatch converts one canonical batch to OpenAI wire values.

type BatchCreateRequest added in v1.2.0

type BatchCreateRequest struct {
	InputFileID      string `json:"input_file_id"`
	Endpoint         string `json:"endpoint"`
	CompletionWindow string `json:"completion_window,omitempty"`
	// Metadata is accepted so a stock SDK call decodes, and it is not
	// stored: this gateway keeps no free-form annotations on a batch.
	Metadata map[string]string `json:"metadata,omitempty"`
}

BatchCreateRequest is the OpenAI batch creation wire request.

type BatchError added in v1.2.0

type BatchError struct {
	Message string `json:"message"`
}

BatchError is one entry inside BatchErrors.

type BatchErrors added in v1.2.0

type BatchErrors struct {
	Object string       `json:"object"`
	Data   []BatchError `json:"data"`
}

BatchErrors states why a failed batch stopped before its lines did.

type BatchLineAnswer added in v1.2.0

type BatchLineAnswer struct {
	StatusCode int             `json:"status_code"`
	RequestID  string          `json:"request_id,omitempty"`
	Body       json.RawMessage `json:"body"`
}

BatchLineAnswer carries what the online route would have answered.

type BatchLineFailure added in v1.2.0

type BatchLineFailure struct {
	Message string `json:"message"`
}

BatchLineFailure mirrors the OpenAI per-line error slot. This gateway reports every failure through the response body instead, the way the online route does, so the slot encodes as null.

type BatchLineRequest added in v1.2.0

type BatchLineRequest struct {
	CustomID string          `json:"custom_id"`
	Method   string          `json:"method"`
	URL      string          `json:"url"`
	Body     json.RawMessage `json:"body"`
}

BatchLineRequest is one wire line of a batch input file.

type BatchLineResponse added in v1.2.0

type BatchLineResponse struct {
	ID       string            `json:"id"`
	CustomID string            `json:"custom_id"`
	Response *BatchLineAnswer  `json:"response"`
	Error    *BatchLineFailure `json:"error"`
}

BatchLineResponse is one wire line of a batch output or error file.

type BatchList added in v1.2.0

type BatchList struct {
	Object  string  `json:"object"`
	Data    []Batch `json:"data"`
	HasMore bool    `json:"has_more"`
}

BatchList is the OpenAI listing of one caller's batches.

func EncodeBatches added in v1.2.0

func EncodeBatches(records []inference.Batch) BatchList

EncodeBatches converts one listing to OpenAI wire values.

type BatchRequestCounts added in v1.2.0

type BatchRequestCounts struct {
	Total     int `json:"total"`
	Completed int `json:"completed"`
	Failed    int `json:"failed"`
}

BatchRequestCounts is the wire progress summary.

type ChatRequest

type ChatRequest struct {
	Model               string            `json:"model"`
	Messages            []Message         `json:"messages"`
	Temperature         *float32          `json:"temperature,omitempty"`
	TopP                *float32          `json:"top_p,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"`
	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"`
	ResponseFormat      *ResponseFormat   `json:"response_format,omitempty"`
	ReasoningEffort     string            `json:"reasoning_effort,omitempty"`
	ParallelToolCalls   *bool             `json:"parallel_tool_calls,omitempty"`
	Store               *bool             `json:"store,omitempty"`
	Metadata            map[string]string `json:"metadata,omitempty"`
	ServiceTier         string            `json:"service_tier,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 OpenAI 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"`
	Choices           []Choice `json:"choices"`
	Usage             Usage    `json:"usage"`
	SystemFingerprint string   `json:"system_fingerprint,omitempty"`
	ServiceTier       string   `json:"service_tier,omitempty"`
}

ChatResponse is the OpenAI chat-completions wire response.

func EncodeChat

func EncodeChat(response inference.ChatResponse) ChatResponse

EncodeChat converts one canonical chat result to OpenAI wire values.

type Choice

type Choice struct {
	Index        int             `json:"index"`
	Message      ResponseMessage `json:"message"`
	FinishReason string          `json:"finish_reason"`
	LogProbs     *LogProbs       `json:"logprobs,omitempty"`
}

Choice is one OpenAI 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 OpenAI 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"`
}

ContentPart is one OpenAI multipart message input.

type Embedding

type Embedding struct {
	Object    string    `json:"object"`
	Index     int       `json:"index"`
	Embedding []float32 `json:"embedding"`
}

Embedding is one OpenAI 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 OpenAI embeddings wire request.

type EmbeddingResponse

type EmbeddingResponse struct {
	Object string      `json:"object"`
	Data   []Embedding `json:"data"`
	Model  string      `json:"model"`
	Usage  Usage       `json:"usage"`
}

EmbeddingResponse is the OpenAI embeddings wire response.

func EncodeEmbedding

func EncodeEmbedding(response inference.EmbeddingResponse) EmbeddingResponse

EncodeEmbedding converts one canonical embedding result to OpenAI wire values.

type ErrorDetail

type ErrorDetail struct {
	Message string  `json:"message"`
	Type    string  `json:"type"`
	Param   *string `json:"param,omitempty"`
	Code    string  `json:"code,omitempty"`
}

ErrorDetail is one OpenAI API error.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse is the OpenAI 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 OpenAI function tool.

type FunctionCall

type FunctionCall struct {
	Name      string `json:"name"`
	Arguments string `json:"arguments"`
}

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 ImageURL

type ImageURL struct {
	URL    string `json:"url"`
	Detail string `json:"detail,omitempty"`
}

ImageURL is an OpenAI image input.

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 OpenAI image generation wire request.

type ImagesResponse added in v1.1.0

type ImagesResponse struct {
	Created int64        `json:"created"`
	Data    []ImageDatum `json:"data"`
	Usage   *Usage       `json:"usage,omitempty"`
}

ImagesResponse is the OpenAI image wire response.

func EncodeImages added in v1.1.0

func EncodeImages(response inference.ImagesResponse) ImagesResponse

EncodeImages converts one canonical image result to OpenAI wire values.

type InputAudio added in v1.1.0

type InputAudio struct {
	Data   string `json:"data"`
	Format string `json:"format,omitempty"`
}

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 Message

type Message struct {
	Role       string          `json:"role"`
	Content    json.RawMessage `json:"content,omitempty"`
	Name       string          `json:"name,omitempty"`
	ToolCalls  []ToolCall      `json:"tool_calls,omitempty"`
	ToolCallID string          `json:"tool_call_id,omitempty"`
	Refusal    string          `json:"refusal,omitempty"`
}

Message is one OpenAI chat message.

type MessageDelta

type MessageDelta struct {
	Role      string     `json:"role,omitempty"`
	Content   string     `json:"content,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, so each chunk holds its own base64 run and
	// the transcript text that goes with it.
	Audio *GeneratedAudio `json:"audio,omitempty"`
}

MessageDelta is one streamed OpenAI message update.

type Model

type Model struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	OwnedBy string `json:"owned_by"`
}

Model is one OpenAI model resource.

type ModelList

type ModelList struct {
	Object string  `json:"object"`
	Data   []Model `json:"data"`
}

ModelList is the OpenAI model-list response.

type ModerationRequest added in v1.2.0

type ModerationRequest struct {
	Model string          `json:"model"`
	Input json.RawMessage `json:"input"`
}

ModerationRequest is the moderation wire request served at POST /v1/moderations. Input stays raw until decode, because its type decides its meaning.

type ModerationResponse added in v1.2.0

type ModerationResponse struct {
	ID      string             `json:"id"`
	Model   string             `json:"model"`
	Results []ModerationResult `json:"results"`
}

ModerationResponse is the moderation wire response.

func EncodeModerations added in v1.2.0

func EncodeModerations(
	response inference.ModerationResponse,
	request inference.ModerationRequest,
) (ModerationResponse, error)

EncodeModerations writes one canonical moderation answer. It validates against the request first, because a result list that answers a different number of inputs reads as ordinary and shifts every verdict onto the wrong input.

type ModerationResult added in v1.2.0

type ModerationResult struct {
	Flagged        bool               `json:"flagged"`
	Categories     map[string]bool    `json:"categories"`
	CategoryScores map[string]float64 `json:"category_scores"`
}

ModerationResult is one input's verdict on the wire. The two maps repeat the wire convention this route's callers parse: a threshold decision per category under categories, and the score behind it under category_scores.

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 RerankDecoding added in v1.1.0

type RerankDecoding struct {
	Request         inference.RerankRequest
	ReturnDocuments bool
}

RerankDecoding is one decoded rerank request with the wire-only options that change how its answer is written. Holding them apart is what keeps the canonical request free of a presentation flag that no router, cache, or usage record has any use for.

func DecodeRerank added in v1.1.0

func DecodeRerank(reader io.Reader) (RerankDecoding, error)

DecodeRerank decodes one strict rerank request. An unknown field fails the same way it fails on the chat route, because a caller that misspells a cost control has to hear about it rather than pay the default.

type RerankRequest added in v1.1.0

type RerankRequest struct {
	Model     string   `json:"model"`
	Query     string   `json:"query"`
	Documents []string `json:"documents"`
	// TopN asks for fewer results. It is not a page: a provider scores every
	// document either way, and it bills for every document either way.
	TopN *int `json:"top_n,omitempty"`
	// ReturnDocuments asks for the ranked text echoed on every result.
	ReturnDocuments bool `json:"return_documents,omitempty"`
	// MaxTokensPerDoc caps how much of each document the provider reads. Not
	// every provider has a wire name for it, and the transport refuses the
	// field rather than dropping it when it cannot say it.
	MaxTokensPerDoc *int `json:"max_tokens_per_doc,omitempty"`
}

RerankRequest is the rerank wire request served at POST /v1/rerank.

type RerankResponse added in v1.1.0

type RerankResponse struct {
	Object  string         `json:"object"`
	Model   string         `json:"model"`
	Results []RerankResult `json:"results"`
	Usage   RerankUsage    `json:"usage"`
}

RerankResponse is the rerank wire response.

func EncodeRerank added in v1.1.0

func EncodeRerank(
	response inference.RerankResponse,
	decoding RerankDecoding,
) (RerankResponse, error)

EncodeRerank writes one canonical rerank answer. It takes the decoding rather than the response alone: an echoed document comes from the request, which is the only copy of the text the gateway holds.

type RerankResult added in v1.1.0

type RerankResult struct {
	Index          int     `json:"index"`
	RelevanceScore float64 `json:"relevance_score"`
	Document       *string `json:"document,omitempty"`
}

RerankResult is one scored document on the wire. The document field is present only when the caller asked for it.

type RerankUsage added in v1.1.0

type RerankUsage struct {
	TotalTokens int `json:"total_tokens,omitempty"`
	SearchUnits int `json:"search_units,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 OpenAI response-format contract.

type ResponseMessage

type ResponseMessage struct {
	Role      string     `json:"role"`
	Content   string     `json:"content"`
	Refusal   *string    `json:"refusal,omitempty"`
	ToolCalls []ToolCall `json:"tool_calls,omitempty"`
	// Images carries generated pictures. The field name comes from the
	// shape the OpenAI-compatible providers that generate images already
	// serve, so a client that reads one of them reads this gateway.
	Images []GeneratedImage `json:"images,omitempty"`
	// Audio carries a spoken answer. Content keeps the transcript beside
	// it rather than going null, because a caller that cannot play audio
	// still has the answer.
	Audio *GeneratedAudio `json:"audio,omitempty"`
}

ResponseMessage is one OpenAI assistant message.

type ResponsesError added in v1.2.0

type ResponsesError struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ResponsesError mirrors the response-level error object. The gateway reports request errors through the error envelope instead, so this field stays null and exists for shape fidelity.

type ResponsesIncompleteDetails added in v1.2.0

type ResponsesIncompleteDetails struct {
	Reason string `json:"reason"`
}

ResponsesIncompleteDetails names why a response stopped early.

type ResponsesInputTokensDetails added in v1.2.0

type ResponsesInputTokensDetails struct {
	CachedTokens int `json:"cached_tokens"`
}

ResponsesInputTokensDetails breaks the input total down.

type ResponsesOutputItem added in v1.2.0

type ResponsesOutputItem struct {
	Type      string                `json:"type"`
	ID        string                `json:"id,omitempty"`
	Status    string                `json:"status,omitempty"`
	Role      string                `json:"role,omitempty"`
	Content   []ResponsesOutputPart `json:"content,omitempty"`
	CallID    string                `json:"call_id,omitempty"`
	Name      string                `json:"name,omitempty"`
	Arguments *string               `json:"arguments,omitempty"`
}

ResponsesOutputItem is one output entry: an assistant message or a function call. Arguments is a pointer so a function call carries the key even while its value is still empty.

type ResponsesOutputPart added in v1.2.0

type ResponsesOutputPart struct {
	Type        string `json:"type"`
	Text        string `json:"text"`
	Annotations []any  `json:"annotations"`
}

ResponsesOutputPart is one message content part.

type ResponsesOutputTokensDetails added in v1.2.0

type ResponsesOutputTokensDetails struct {
	ReasoningTokens int `json:"reasoning_tokens"`
}

ResponsesOutputTokensDetails breaks the output total down.

type ResponsesReasoningConfig added in v1.2.0

type ResponsesReasoningConfig struct {
	Effort string `json:"effort,omitempty"`
}

ResponsesReasoningConfig selects the reasoning depth.

type ResponsesRequest added in v1.2.0

type ResponsesRequest struct {
	Model              string                    `json:"model"`
	Input              json.RawMessage           `json:"input"`
	Instructions       string                    `json:"instructions,omitempty"`
	Temperature        *float32                  `json:"temperature,omitempty"`
	TopP               *float32                  `json:"top_p,omitempty"`
	MaxOutputTokens    *int                      `json:"max_output_tokens,omitempty"`
	Stream             bool                      `json:"stream,omitempty"`
	User               string                    `json:"user,omitempty"`
	Tools              []ResponsesTool           `json:"tools,omitempty"`
	ToolChoice         json.RawMessage           `json:"tool_choice,omitempty"`
	ParallelToolCalls  *bool                     `json:"parallel_tool_calls,omitempty"`
	Text               *ResponsesTextConfig      `json:"text,omitempty"`
	Reasoning          *ResponsesReasoningConfig `json:"reasoning,omitempty"`
	PreviousResponseID *string                   `json:"previous_response_id,omitempty"`
	Store              *bool                     `json:"store,omitempty"`
}

ResponsesRequest is the OpenAI Responses wire request. The stored-state fields previous_response_id and store are declared so a caller that sets one reads a refusal that names it, not an unknown-field error.

type ResponsesResponse added in v1.2.0

type ResponsesResponse struct {
	ID                string                      `json:"id"`
	Object            string                      `json:"object"`
	CreatedAt         int64                       `json:"created_at"`
	Status            string                      `json:"status"`
	Error             *ResponsesError             `json:"error"`
	IncompleteDetails *ResponsesIncompleteDetails `json:"incomplete_details"`
	Model             string                      `json:"model"`
	Output            []ResponsesOutputItem       `json:"output"`
	ParallelToolCalls bool                        `json:"parallel_tool_calls"`
	ToolChoice        string                      `json:"tool_choice"`
	Tools             []ResponsesTool             `json:"tools"`
	Usage             *ResponsesUsage             `json:"usage,omitempty"`
}

ResponsesResponse is the OpenAI Responses wire response. Error and incomplete_details serialize as explicit nulls because SDK readers expect the keys to exist.

func EncodeResponses added in v1.2.0

func EncodeResponses(response inference.ChatResponse) ResponsesResponse

EncodeResponses encodes one canonical chat response as a Responses object. The first choice becomes the output: its text becomes one message item and each tool call becomes one function_call item.

type ResponsesStreamEncoder added in v1.2.0

type ResponsesStreamEncoder struct {
	// contains filtered or unexported fields
}

ResponsesStreamEncoder folds the canonical stream into the named Responses event sequence. It is stateful: it numbers every event, accumulates the output items, and closes them in order. Call Encode for each canonical event and Finish after the stream ends.

func (*ResponsesStreamEncoder) Encode added in v1.2.0

Encode folds one canonical stream event into zero or more named events.

func (*ResponsesStreamEncoder) Finish added in v1.2.0

Finish closes any open item and emits the terminal snapshot event.

type ResponsesStreamEvent added in v1.2.0

type ResponsesStreamEvent struct {
	Type string
	Data json.RawMessage
}

ResponsesStreamEvent is one named server-sent event: the event name and its JSON payload. The Responses stream ends with response.completed and carries no [DONE] terminator.

type ResponsesTextConfig added in v1.2.0

type ResponsesTextConfig struct {
	Format *ResponsesTextFormat `json:"format,omitempty"`
}

ResponsesTextConfig carries the structured-output selection.

type ResponsesTextFormat added in v1.2.0

type ResponsesTextFormat struct {
	Type        string          `json:"type"`
	Name        string          `json:"name,omitempty"`
	Description string          `json:"description,omitempty"`
	Schema      json.RawMessage `json:"schema,omitempty"`
	Strict      bool            `json:"strict,omitempty"`
}

ResponsesTextFormat is the Responses spelling of response_format.

type ResponsesTool added in v1.2.0

type ResponsesTool struct {
	Type        string          `json:"type"`
	Name        string          `json:"name,omitempty"`
	Description string          `json:"description,omitempty"`
	Parameters  json.RawMessage `json:"parameters,omitempty"`
	Strict      *bool           `json:"strict,omitempty"`
}

ResponsesTool is one Responses tool declaration. The shape is flat where the chat shape nests a function object.

type ResponsesUsage added in v1.2.0

type ResponsesUsage struct {
	InputTokens         int                          `json:"input_tokens"`
	InputTokensDetails  ResponsesInputTokensDetails  `json:"input_tokens_details"`
	OutputTokens        int                          `json:"output_tokens"`
	OutputTokensDetails ResponsesOutputTokensDetails `json:"output_tokens_details"`
	TotalTokens         int                          `json:"total_tokens"`
}

ResponsesUsage is the Responses spelling of token usage.

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 OpenAI text-to-speech wire request.

type StoredFile added in v1.1.0

type StoredFile struct {
	ID        string `json:"id"`
	Object    string `json:"object"`
	Bytes     int64  `json:"bytes"`
	CreatedAt int64  `json:"created_at"`
	Filename  string `json:"filename"`
	Purpose   string `json:"purpose"`
	ExpiresAt int64  `json:"expires_at,omitempty"`
	Status    string `json:"status"`
}

StoredFile is one file object on the wire.

The status_details field is absent. Upstream fills it from fine-tune validation, Starport validates no fine-tune file, and a field carrying an invented value is worse than an absent one.

type StoredFileDeletion added in v1.1.0

type StoredFileDeletion struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Deleted bool   `json:"deleted"`
}

StoredFileDeletion is the answer to a delete.

func NewStoredFileDeletion added in v1.1.0

func NewStoredFileDeletion(id string) StoredFileDeletion

NewStoredFileDeletion names one deleted file.

type StoredFileList added in v1.1.0

type StoredFileList struct {
	Object  string       `json:"object"`
	Data    []StoredFile `json:"data"`
	FirstID string       `json:"first_id,omitempty"`
	LastID  string       `json:"last_id,omitempty"`
	HasMore bool         `json:"has_more"`
}

StoredFileList is the list envelope.

HasMore has no omitempty. A client reads the field to decide whether to page again, and an absent false would read the same as an absent envelope.

func NewStoredFileList added in v1.1.0

func NewStoredFileList(page []StoredFile, hasMore bool) StoredFileList

NewStoredFileList wraps one page and names its edges.

The cursor fields come from the page rather than from the caller, so a client that pages with last_id reads the same order the server returned.

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 OpenAI choice.

type StreamChunk

type StreamChunk struct {
	ID                string         `json:"id"`
	Object            string         `json:"object"`
	Created           int64          `json:"created"`
	Model             string         `json:"model"`
	Choices           []StreamChoice `json:"choices"`
	Usage             *Usage         `json:"usage,omitempty"`
	SystemFingerprint string         `json:"system_fingerprint,omitempty"`
}

StreamChunk is one OpenAI SSE data value.

func EncodeStream

func EncodeStream(event inference.StreamEvent) StreamChunk

EncodeStream converts one canonical stream event to an OpenAI chunk.

type StreamOptions

type StreamOptions struct {
	IncludeUsage bool `json:"include_usage,omitempty"`
}

StreamOptions controls OpenAI stream usage events.

type Tool

type Tool struct {
	Type     string   `json:"type"`
	Function Function `json:"function"`
}

Tool is an OpenAI function tool.

type ToolCall

type ToolCall struct {
	ID       string       `json:"id"`
	Type     string       `json:"type"`
	Function FunctionCall `json:"function"`
}

ToolCall is an OpenAI 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 TranscriptionResponse added in v1.1.0

type TranscriptionResponse struct {
	Text     string  `json:"text"`
	Language string  `json:"language,omitempty"`
	Duration float64 `json:"duration,omitempty"`
}

TranscriptionResponse is the OpenAI speech-to-text wire response.

func EncodeTranscription added in v1.1.0

func EncodeTranscription(response inference.TranscriptionResponse) TranscriptionResponse

EncodeTranscription converts one canonical transcript to OpenAI wire values.

type UnsupportedError added in v1.2.0

type UnsupportedError struct {
	Param   string
	Message string
}

UnsupportedError names one Responses API field the gateway refuses, because honoring it needs stored state the gateway does not keep. The controller maps it to a 400 whose param is the refused field.

func (*UnsupportedError) Error added in v1.2.0

func (e *UnsupportedError) Error() string

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 OpenAI token accounting.

type VideoJob added in v1.1.0

type VideoJob struct {
	ID          string         `json:"id"`
	Object      string         `json:"object"`
	Model       string         `json:"model"`
	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 OpenAI video wire object.

func EncodeVideoJob added in v1.1.0

func EncodeVideoJob(job inference.VideoJob) VideoJob

EncodeVideoJob converts one canonical job to OpenAI 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 {
	Object string     `json:"object"`
	Data   []VideoJob `json:"data"`
}

VideoJobList is the OpenAI 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 OpenAI 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 OpenAI video wire request.

type VideoURL added in v1.1.0

type VideoURL struct {
	URL string `json:"url"`
}

VideoURL is a video input.

Jump to

Keyboard shortcuts

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