openairesp

package
v0.15.3 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package openairesp is the openai-responses dialect: POST {base_url}/responses, OpenAI's Responses API (docs/design.md §7.2). The built-in openai profile speaks it, and any OpenAI-shaped server that serves /v1/responses can opt in with `dialect: openai-responses` (vLLM does).

Like openai-chat it is written on net/http and its own wire types, not an SDK: pointer-typed wire structs keep a count the server never sent distinct from a zero it did, servers differ in what they return (vLLM puts reasoning in reasoning_text content, OpenAI in summaries and encrypted content), and no new module enters the graph.

Requests are stateless: store false, with the reasoning's encrypted content requested and carried forward through genai.Part.ThoughtSignature, so a tool loop keeps its reasoning without a server-side conversation.

Retries happen in the HTTP client (package retry), so every attempt gets a fresh credential and a provider's Retry-After is honored.

Index

Constants

View Source
const (
	// RefusalKey marks a response whose text is the model's refusal.
	RefusalKey = "core_models.refusal"
	// FinishReasonKey holds a finish reason with no genai equivalent.
	FinishReasonKey = "core_models.finish_reason"
	// ToolChoiceKey marks a response whose request asked for a forced
	// tool call the model cannot take, and was sent with "auto" instead.
	ToolChoiceKey = "core_models.tool_choice_downgraded"
	// DroppedParamsKey lists the optional fields left off this request
	// because the model refuses them ("include", "temperature", "top_p");
	// see dropOn.
	DroppedParamsKey = "core_models.dropped_params"
)

Metadata keys this dialect writes beside usage.MetadataKey. The values match openaichat's, so a product reads one key for both.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	StatusCode int
	Type       string
	Code       string
	Message    string
	// Param is the request field the server blamed, when it named one.
	Param string
}

APIError is a non-2xx answer, an error event inside a stream, or a response whose status is failed. StatusCode is 0 for the last two.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) HTTPStatus

func (e *APIError) HTTPStatus() int

HTTPStatus reports the status, for retry classifiers above this package. Zero for a failure reported inside a 200 response.

type Client

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

Client is a connection to one server. Safe for concurrent use.

func New

func New(opts Options) (*Client, error)

New returns a Client for opts.

func (*Client) Model

func (c *Client) Model(id string) llm.LLM

Model returns the model id on this server as an llm.LLM.

func (*Client) ModelWith

func (c *Client) ModelWith(id string, mo ModelOptions) llm.LLM

ModelWith returns the model id with mo laid over the Client's options.

type ModelOptions

type ModelOptions struct {
	ResponseSchema     *bool
	ReasoningEcho      *bool
	NoForcedToolChoice *bool
	// ExtraBody, when non-nil, replaces the Client's.
	ExtraBody map[string]any
}

ModelOptions are the per-model refinements of Options.

type Options

type Options struct {
	// BaseURL is the API root; requests go to BaseURL + "/responses".
	BaseURL string
	// Credential authenticates every request as a bearer token. Nil
	// sends none.
	Credential *auth.Credential
	// HTTPClient supplies the base transport and timeout. Nil means a
	// client with http.DefaultTransport. coremodels.Open puts a profile's
	// headers in it (profile.Resolved.HeaderTransport); a host building
	// this client itself does the same.
	HTTPClient *http.Client
	// Retry is the HTTP-layer retry policy. Nil means retry.Default().
	Retry *retry.Policy

	// Backend and Region are stamped into every usage.Detail.
	Backend string
	Region  string

	// ResponseSchema: the server enforces text.format json_schema. A
	// request that needs one is refused when false.
	ResponseSchema bool
	// ReasoningEcho: carry reasoning forward between turns — request its
	// encrypted content and replay it as a reasoning item. When false,
	// neither happens.
	ReasoningEcho bool
	// CachedTokensUnreliable: record cached tokens as not reported even
	// when the server sends them.
	CachedTokensUnreliable bool
	// NoForcedToolChoice: the model rejects "required" and named tool
	// choices; send "auto" instead and mark the response.
	NoForcedToolChoice bool
	// ExtraBody is merged into every request body: vendor fields the
	// dialect does not model. It must not repeat a field the adapter sets.
	ExtraBody map[string]any
}

Options configures a Client. A coremodels.Open caller never builds one by hand; it comes from a resolved profile.

Jump to

Keyboard shortcuts

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