Documentation
¶
Overview ¶
Package openai implements reusable OpenAI wire adapters for native and compatible provider endpoints.
A nonempty Config BaseURL overrides OPENAI_BASE_URL; an absent environment value uses the SDK production endpoint. Construction validates and freezes only that effective URL. Official SDK service constructors apply the binding's explicit credentials, endpoint, headers, and HTTP client without inheriting unrelated SDK environment settings.
Chat Completions accepts typed tools with identifiable calls. Deprecated functions cannot be replayed as modern tool results. Native credential, response identity and tool or embedding indexes never default to another response or input. Core embeddings use numeric float vectors.
Unary JSON responses and HTTP error envelopes are admitted within Core's httpclient.DefaultMaxJSONResponseBytes before SDK decoding. Successful SSE uses that budget per wire event, including its framing, and has no aggregate ceiling. SpeechModelConfig.MaxResponseBytes bounds Call's aggregate audio; Stream remains incremental. An oversized result never becomes partial success.
Modalities exposed:
- chat (Chat Completions) via NewChatCompletions — tool calling, streaming, native request extensions, vision input, audio input/output;
- chat (Responses) via NewResponses — ordered reasoning and tool replay, streaming, multimodal input, and complete-request input-token counting through the native Responses endpoint;
- embedding via NewEmbeddingModel — text-embedding-3-small/large with dimension truncation;
- image via NewImageModel — GPT image generation;
- moderation via NewModerationModel — omni-moderation-latest;
- speech via NewSpeechModel — tts-1, tts-1-hd, gpt-4o-mini-tts;
- audio transcription via NewTranscriptionModel — whisper-1, gpt-4o-transcribe, gpt-4o-mini-transcribe;
- audio translation via NewAudioTranslationModel — whisper-1 translating any source language to English (implements transcription.Model).
ChatCompletions.ListModels and Responses.ListModels discover IDs visible to the same credential, endpoint, and HTTP client. Discovery uses the SDK's Models endpoint with caller-supplied count, byte, and context budgets. Results are complete or fail without exposing partial IDs; catalog enrichment, selection, sorting, and deduplication remain consumer policy.
Model id constants aren't exported here — they're maintained by openai-go (openai.ChatModelGPT5_6Sol, openai.EmbeddingModelTextEmbedding3Large, etc.). Import openai-go directly when you need them.
Provider-specific fields not modeled by Core reach the wire through request extensions scoped to the endpoint provider. Raw response details use that same namespace, so compatible endpoints never leak OpenAI provider metadata. Core ownership does not depend on endpoint support: unsupported Core options remain reserved in raw extensions and dialect callbacks. Responses rejects native frequency_penalty, presence_penalty, top_k, and stop. Image dimensions belong to Core and project to size; seed and negative_prompt remain unsupported. Image response_format selects native delivery, independently of Core's image MIME OutputFormat, and remains available through the extension. Audio transcription and translation extensions use the SDK's typed multipart fields. Unknown fields, nulls, and empty arrays are rejected because the SDK cannot preserve them in that form. Their response_format must select JSON; text, srt, and vtt require a different decoder. Image, transcription, and translation calls own their unary mode, so extensions cannot enable streaming. Image output formats are PNG, JPEG, and WebP. Reported response formats own the generated media's MIME type; an absent format uses the requested format or the provider's PNG default. Unknown response formats are invalid responses.
Chat Completions owns its single output. Neither a raw request extension nor a compatible dialect can set n. Core Options.TopK is projected only when the binding's SupportsTopK facet is enabled. Neither raw extensions nor request callbacks may supply top_k. Standard Chat Completions requests stream_options.include_usage by default for both Call and Stream. Explicit false or null stream_options are respected; compatible providers retain their own request policy. Missing provider usage remains unknown, never a fabricated zero. Generated Chat audio retains its bytes and provider replay ID together. Assistant audio with an inline payload uses Media.ID for replay; provider references remain valid without an inline payload. Responses rejects assistant media history that its input projection cannot represent. Responses tools use non-strict mode to preserve the caller's optional JSON Schema properties. Inline file inputs and tool outputs retain their declared MIME in a data URL; bare base64 cannot establish the file type expected by the Responses API.
Strict output schemas keep the caller's accepted values: representable allOf intersections are lowered once for Chat Completions and Responses. Optional properties, open objects, and unsupported constraints fail locally with chat.ErrUnsupportedOutputFormat rather than changing the domain contract.
Responses Call and Stream share terminal-state mapping: incomplete generation preserves its stop reason, failed generation returns an error, and a stream ending before a terminal response returns chat.ErrInvalidResponse. Each Responses reasoning segment keeps a distinct Core Part. Part.Text owns visible summary or content text; ReasoningState retains segment identities and one completed native item without text copies. Replay requires that complete state and its Core text parts from the same provider. Frames carry the issuing binding's provider namespace; foreign state is omitted from native replay. Unscoped frames and full native items are rejected. Preserve signed content and native fields when replaying. Completed reasoning must agree with streamed text and its item completion; contradictory or unfinished items cannot produce a successful terminal delta. Assistant message identity and phase remain separate from visible text so commentary and final answers retain their original boundaries during replay.
Provider packages with an OpenAI-compatible endpoint reuse the protocol through NewChatCompletions and select one typed DialectConfig. This keeps provider-only fields such as reasoning_content out of OpenAI's native behavior while sharing the standard wire mapping. Construction freezes that configuration; its provider namespace supplies both extension keys and the reasoning codec's replay issuer. Later configuration edits cannot relabel previously constructed adapters. APIKey alone supplies credentials; Headers cannot replace or add a second authentication source. Moderation reads the native category flags and scores before the SDK's scalar fields can erase absence. Each reported category needs both a flag and score; future category names are retained. Slash and hyphen normalization must not collide, and missing flags never become false.
Index ¶
- Constants
- func NewTextReasoningPart(provider string, field TextReasoningField, text string) (corechat.Part, error)
- func RequestStreamUsage(_ *corechat.Request, target *CompatibleRequest) error
- type AudioTranslationModel
- type AudioTranslationModelConfig
- type ChatCompletions
- func (c *ChatCompletions) Call(ctx context.Context, req *corechat.Request) (*corechat.Response, error)
- func (c *ChatCompletions) ListModels(ctx context.Context, maxModels int, maxResponseBytes int64) ([]string, error)
- func (c *ChatCompletions) Stream(ctx context.Context, req *corechat.Request) iter.Seq2[*corechat.ResponseDelta, error]
- type ChatCompletionsConfig
- type ChatOption
- type CompatibleRequest
- func (c *CompatibleRequest) Model() string
- func (c *CompatibleRequest) SetExtraField(name string, value any) error
- func (c *CompatibleRequest) SetFinalAssistantExtraField(name string, value any) error
- func (c *CompatibleRequest) Stream() bool
- func (c *CompatibleRequest) Temperature() (float64, bool)
- func (c *CompatibleRequest) TopP() (float64, bool)
- type CompatibleResponsesRequest
- type DialectConfig
- type EmbeddingModel
- type EmbeddingModelConfig
- type ImageModel
- type ImageModelConfig
- type ModerationModel
- type ModerationModelConfig
- type ReasoningDetailsConfig
- type RequestFields
- type Responses
- func (r *Responses) Call(ctx context.Context, req *corechat.Request) (*corechat.Response, error)
- func (r *Responses) CountInputTokens(ctx context.Context, req *corechat.Request) (int64, error)
- func (r *Responses) ListModels(ctx context.Context, maxModels int, maxResponseBytes int64) ([]string, error)
- func (r *Responses) Stream(ctx context.Context, req *corechat.Request) iter.Seq2[*corechat.ResponseDelta, error]
- type ResponsesConfig
- type ResponsesDialect
- type SpeechModel
- type SpeechModelConfig
- type TextReasoningConfig
- type TextReasoningField
- type TextReasoningReplay
- type TokenLimitField
- type TranscriptionModel
- type TranscriptionModelConfig
Examples ¶
Constants ¶
const ( // RequestExtensionKey identifies provider-owned Chat Completions fields // encoded as [RequestFields]. RequestExtensionKey = ProviderID + "/request" // StreamChunkExtensionKey preserves each complete official Chat // Completions stream chunk. StreamChunkExtensionKey = ProviderID + "/stream_chunk" )
const ( CompatibleRequestExtensionSuffix = "/openai_request" CompatibleStreamExtensionSuffix = "/openai_stream_chunk" )
const ( ProviderID = "openai" SpeechRequestExtensionKey = ProviderID + "/speech_request" TranscriptionRequestExtensionKey = ProviderID + "/transcription_request" TranslationRequestExtensionKey = ProviderID + "/translation_request" EmbeddingRequestExtensionKey = ProviderID + "/embedding_request" ImageRequestExtensionKey = ProviderID + "/image_request" ModerationRequestExtensionKey = ProviderID + "/moderation_request" )
Namespacing preserves provider-specific data without promoting it into the shared Core protocol or colliding with another provider.
const ( ResponsesRequestExtensionSuffix = "/responses_request" ResponsesResponseExtensionSuffix = "/responses_response" // Native fields without a Core equivalent retain the binding's namespace. ResponsesRequestExtensionKey = ProviderID + ResponsesRequestExtensionSuffix ResponsesResponseExtensionKey = ProviderID + ResponsesResponseExtensionSuffix )
Variables ¶
This section is empty.
Functions ¶
func NewTextReasoningPart ¶
func NewTextReasoningPart(provider string, field TextReasoningField, text string) (corechat.Part, error)
NewTextReasoningPart retains the issuing field because providers require the same property during replay even when another model uses a different one.
func RequestStreamUsage ¶ added in v0.59.0
func RequestStreamUsage(_ *corechat.Request, target *CompatibleRequest) error
Types ¶
type AudioTranslationModel ¶
type AudioTranslationModel struct {
// contains filtered or unexported fields
}
AudioTranslationModel exposes OpenAI's /audio/translations endpoint — it accepts audio in any supported language and returns the **English** translation. The wire shape is the same as transcription (audio in, text out), so it implements the transcription.Model interface and can drop into any code path that already uses transcription.
If the caller needs the original-language transcript instead of a translation, use TranscriptionModel.
func NewAudioTranslationModel ¶
func NewAudioTranslationModel(ctx context.Context, config AudioTranslationModelConfig) (*AudioTranslationModel, error)
NewAudioTranslationModel binds a provider's synchronous multipart audio/translations endpoint. It requires this exact upload capability; a realtime translation session does not implement the same operation.
func (*AudioTranslationModel) Call ¶
func (a *AudioTranslationModel) Call(ctx context.Context, req *transcription.Request) (*transcription.Response, error)
type AudioTranslationModelConfig ¶
type AudioTranslationModelConfig struct {
Provider string
APIKey string
DefaultOptions transcription.Options
BaseURL string
HTTPClient *http.Client
}
Only "whisper-1" is currently accepted by OpenAI — newer gpt-4o-transcribe models are transcription-only and reject translation calls.
func (AudioTranslationModelConfig) Validate ¶
func (a AudioTranslationModelConfig) Validate() error
type ChatCompletions ¶ added in v0.13.0
type ChatCompletions struct {
// contains filtered or unexported fields
}
ChatCompletions implements OpenAI's Chat Completions protocol and is also the reusable protocol base for provider packages exposing a compatible endpoint.
func NewChatCompletions ¶ added in v0.13.0
func NewChatCompletions(ctx context.Context, config ChatCompletionsConfig, dialect DialectConfig) (*ChatCompletions, error)
func (*ChatCompletions) ListModels ¶ added in v0.40.0
func (c *ChatCompletions) ListModels(ctx context.Context, maxModels int, maxResponseBytes int64) ([]string, error)
ListModels returns the model IDs visible to this binding in provider order. Both limits must be positive. maxResponseBytes bounds the total response bytes across all pages; maxModels counts advertised entries, including duplicates. Failure or incomplete pagination returns no IDs. The caller owns the deadline; discovery performs no retries and preserves HTTPStatus and HTTPHeader errors.
func (*ChatCompletions) Stream ¶ added in v0.13.0
func (c *ChatCompletions) Stream(ctx context.Context, req *corechat.Request) iter.Seq2[*corechat.ResponseDelta, error]
Stream performs one streaming Chat Completions request. Stable tool identity is retained in adapter-local state until each incomplete wire delta can be expressed as a Core response delta. Generation after a native finish reason returns corechat.ErrInvalidResponse; audio expiry and usage metadata may follow it. Successful termination is yielded only after the transport ends.
type ChatCompletionsConfig ¶ added in v0.13.0
type ChatCompletionsConfig struct {
APIKey string
DefaultOptions corechat.Options
BaseURL string
HTTPClient *http.Client
Headers http.Header
}
DefaultOptions are copied during construction; callers may select the model per request.
func (ChatCompletionsConfig) Validate ¶ added in v0.13.0
func (c ChatCompletionsConfig) Validate() error
type ChatOption ¶ added in v0.16.0
type ChatOption string
ChatOption names one Core chat option by the OpenAI request field it travels as. It exists so a dialect can declare which of them its provider discards.
const ( ChatOptionFrequencyPenalty ChatOption = "frequency_penalty" ChatOptionPresencePenalty ChatOption = "presence_penalty" ChatOptionReasoningEffort ChatOption = "reasoning_effort" ChatOptionTemperature ChatOption = "temperature" ChatOptionTopP ChatOption = "top_p" )
type CompatibleRequest ¶
type CompatibleRequest struct {
// contains filtered or unexported fields
}
CompatibleRequest exposes the stable subset of a compatible request that a provider dialect may inspect. Core-owned fields cannot be replaced; OpenAI SDK wire types never cross this boundary.
func (*CompatibleRequest) Model ¶
func (c *CompatibleRequest) Model() string
Model returns the effective model after Core defaults and request options have been merged.
func (*CompatibleRequest) SetExtraField ¶
func (c *CompatibleRequest) SetExtraField(name string, value any) error
SetExtraField adds or replaces one provider-owned top-level JSON field.
func (*CompatibleRequest) SetFinalAssistantExtraField ¶ added in v0.60.0
func (c *CompatibleRequest) SetFinalAssistantExtraField(name string, value any) error
Provider prefix-continuation flags belong to the final assistant message, while its role, content and tool calls remain owned by the Core projection.
func (*CompatibleRequest) Stream ¶
func (c *CompatibleRequest) Stream() bool
func (*CompatibleRequest) Temperature ¶
func (c *CompatibleRequest) Temperature() (float64, bool)
Temperature returns the effective temperature when one was supplied.
func (*CompatibleRequest) TopP ¶ added in v0.16.0
func (c *CompatibleRequest) TopP() (float64, bool)
TopP returns the effective nucleus-sampling value when one was supplied. It is exposed for the same reason as Temperature: a provider that overrides or bounds it can only say so about the value that will actually be sent, which is the merged one rather than the request's own.
type CompatibleResponsesRequest ¶ added in v0.57.0
type CompatibleResponsesRequest struct {
Include []string
Store *bool
BuiltInTools []json.RawMessage
// contains filtered or unexported fields
}
CompatibleResponsesRequest exposes only provider-owned Responses controls. BuiltInTools are appended to Core's function tools; a non-nil empty slice explicitly sends that remaining tool list. SDK wire types stay private.
func (*CompatibleResponsesRequest) SetExtraField ¶ added in v0.57.0
func (c *CompatibleResponsesRequest) SetExtraField(name string, value any) error
func (CompatibleResponsesRequest) Validate ¶ added in v0.57.0
func (c CompatibleResponsesRequest) Validate() error
type DialectConfig ¶ added in v0.60.0
type DialectConfig struct {
// Provider scopes provider-owned response and replay state.
Provider string
PrepareRequest func(source *corechat.Request, target *CompatibleRequest) error
TokenLimitField TokenLimitField
// SupportsTopK enables the Core option's wire projection for compatible
// endpoints that support it. Raw request extensions never own this field.
SupportsTopK bool
// NativeOutputFormat reports whether this compatible endpoint natively
// supports a Core output format. A nil function means the full OpenAI response_format
// surface is supported. Unsupported formats return ErrUnsupportedOutputFormat.
NativeOutputFormat func(corechat.OutputFormatType) bool
// DisableRawRequestExtension prevents provider adapters from accepting an
// arbitrary OpenAI request object when their documented request surface is
// narrower than OpenAI's.
DisableRawRequestExtension bool
// IgnoredOptions names the Core options this endpoint accepts on the wire
// and then discards. A compatible provider that publishes such a list --
// Anthropic's marks reasoning_effort, presence_penalty and
// frequency_penalty "Ignored" -- makes a populated option vanish between
// Call and the model, which reads exactly like the adapter dropping it.
// Naming them here refuses the option instead, so the caller learns at the
// call that this endpoint cannot honor it.
IgnoredOptions []ChatOption
// MaxTemperature bounds Options.Temperature for a provider that documents a
// narrower range than OpenAI's. Refusing beats sending an out-of-range
// value, whose fate the provider decides: Anthropic's table says it is
// "capped at 1", which alters the request silently, while others answer an
// error further from the caller. Nil accepts whatever Core accepts.
MaxTemperature *float64
TextReasoning *TextReasoningConfig
ReasoningDetails *ReasoningDetailsConfig
}
DialectConfig groups the independently typed request and response protocol facets selected by a provider adapter. One Chat Completions adapter has exactly one dialect. Construction snapshots its mutable policy values; callback captures remain owned by the caller. PrepareRequest receives an independently owned request with resolved options after Core projection. Only target changes affect the wire request; source edits never change the caller's history.
func (DialectConfig) Validate ¶ added in v0.60.0
func (d DialectConfig) Validate() error
type EmbeddingModel ¶
type EmbeddingModel struct {
// contains filtered or unexported fields
}
func NewEmbeddingModel ¶
func NewEmbeddingModel(ctx context.Context, config EmbeddingModelConfig) (*EmbeddingModel, error)
type EmbeddingModelConfig ¶
type EmbeddingModelConfig struct {
Provider string
APIKey string
DefaultOptions embedding.Options
BaseURL string
HTTPClient *http.Client
}
func (EmbeddingModelConfig) Validate ¶
func (e EmbeddingModelConfig) Validate() error
type ImageModel ¶
type ImageModel struct {
// contains filtered or unexported fields
}
func NewImageModel ¶
func NewImageModel(ctx context.Context, config ImageModelConfig) (*ImageModel, error)
type ImageModelConfig ¶
type ImageModelConfig struct {
Provider string
APIKey string
DefaultOptions image.Options
BaseURL string
HTTPClient *http.Client
}
func (ImageModelConfig) Validate ¶
func (i ImageModelConfig) Validate() error
type ModerationModel ¶
type ModerationModel struct {
// contains filtered or unexported fields
}
func NewModerationModel ¶
func NewModerationModel(ctx context.Context, config ModerationModelConfig) (*ModerationModel, error)
func (*ModerationModel) Call ¶
func (m *ModerationModel) Call(ctx context.Context, req *moderation.Request) (*moderation.Response, error)
type ModerationModelConfig ¶
type ModerationModelConfig struct {
Provider string
APIKey string
DefaultOptions moderation.Options
BaseURL string
HTTPClient *http.Client
}
func (ModerationModelConfig) Validate ¶
func (m ModerationModelConfig) Validate() error
type ReasoningDetailsConfig ¶
type ReasoningDetailsConfig struct {
TextField string
DetailsField string
// ReplayPlainText replays only text issued by this provider and wire field.
// Foreign native state never becomes a plain-text replay for this issuer.
ReplayPlainText bool
}
ReasoningDetailsConfig describes the structured reasoning_details dialect shared by several OpenAI-compatible providers. The final binding supplies the issuer, so this wire configuration cannot select another replay owner.
func (ReasoningDetailsConfig) Validate ¶
func (r ReasoningDetailsConfig) Validate() error
type RequestFields ¶
RequestFields contains provider-owned top-level JSON fields that are not represented by Core. Fields owned by Core are rejected instead of allowing an extension to silently override the neutral request. Numbers decoded from extensions remain json.Number until a typed/native projection chooses their representation.
type Responses ¶ added in v0.13.0
type Responses struct {
// contains filtered or unexported fields
}
Responses adapts OpenAI's ordered Responses API output to the minimal Core chat Model and Streamer capabilities.
func NewResponses ¶ added in v0.13.0
func NewResponses(ctx context.Context, config ResponsesConfig, dialect ResponsesDialect) (*Responses, error)
NewResponses shares the Responses event lifecycle with a provider that explicitly implements it. Provider wrappers expose only supported optional capabilities such as model discovery or input-token counting.
func (*Responses) CountInputTokens ¶ added in v0.13.0
CountInputTokens calls the provider's Responses input-token endpoint with the same provider request projection used by Call.
func (*Responses) ListModels ¶ added in v0.40.0
func (r *Responses) ListModels(ctx context.Context, maxModels int, maxResponseBytes int64) ([]string, error)
ListModels returns the model IDs visible to this binding in provider order. Both limits must be positive. maxResponseBytes bounds the total response bytes across all pages; maxModels counts advertised entries, including duplicates. Failure or incomplete pagination returns no IDs. The caller owns the deadline; discovery performs no retries and preserves HTTPStatus and HTTPHeader errors.
Example ¶
var calls atomic.Int32
server := httptest.NewServer(http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "application/json")
if calls.Add(1) == 1 {
_, _ = io.WriteString(writer, `{"data":[{"id":"first"},{"id":"second"}]}`)
return
}
writer.Header().Set("Retry-After", "3")
writer.WriteHeader(http.StatusTooManyRequests)
_, _ = io.WriteString(writer, `{"error":{"message":"slow down","type":"rate_limit_error"}}`)
}))
defer server.Close()
model, err := openai.NewResponses(context.Background(), openai.ResponsesConfig{
APIKey: "test-key", BaseURL: server.URL + "/v1", HTTPClient: server.Client(),
}, testResponsesDialect(),
)
if err != nil {
fmt.Println(err)
return
}
ids, err := model.ListModels(context.Background(), 10, 1024)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(ids)
_, err = model.ListModels(context.Background(), 10, 1024)
type httpFailure interface {
error
HTTPStatus() int
HTTPHeader() http.Header
}
if failure, ok := errors.AsType[httpFailure](err); ok {
fmt.Printf("status: %d, retry after: %s\n", failure.HTTPStatus(), failure.HTTPHeader().Get("Retry-After"))
}
Output: [first second] status: 429, retry after: 3
func (*Responses) Stream ¶ added in v0.13.0
func (r *Responses) Stream(ctx context.Context, req *corechat.Request) iter.Seq2[*corechat.ResponseDelta, error]
Stream performs one streaming Responses API request and yields ordered Core response deltas. Each function-call item owns its fixed call identity and open lifetime. Native item IDs bind when first reported; omitted IDs never replace a known identity. Reused identities, changed correlations, or arguments after item completion return corechat.ErrInvalidResponse. Incomplete responses may preserve a tool whose generation did not reach item completion. Completion is published after the native body ends successfully; later events are invalid.
type ResponsesConfig ¶ added in v0.13.0
type ResponsesConfig struct {
APIKey string
DefaultOptions corechat.Options
BaseURL string
HTTPClient *http.Client
Headers http.Header
}
DefaultOptions are copied during construction; callers may select the model per request.
func (ResponsesConfig) Validate ¶ added in v0.13.0
func (r ResponsesConfig) Validate() error
type ResponsesDialect ¶ added in v0.57.0
type ResponsesDialect struct {
Provider string
PrepareRequest func(*corechat.Request, *CompatibleResponsesRequest) error
DisableRawRequestExtension bool
PreserveStreamEvents bool
}
ResponsesDialect binds one provider's Responses-compatible endpoint. The callback runs after Core projection and before transport. Raw request fields are provider-namespaced; adapters with a typed extension can disable them. PrepareRequest receives an independently owned request with resolved options. Only target changes affect the wire request; source edits never change the caller's history.
func (ResponsesDialect) Validate ¶ added in v0.57.0
func (r ResponsesDialect) Validate() error
type SpeechModel ¶ added in v0.41.0
type SpeechModel struct {
// contains filtered or unexported fields
}
func NewSpeechModel ¶ added in v0.41.0
func NewSpeechModel(ctx context.Context, config SpeechModelConfig) (*SpeechModel, error)
type SpeechModelConfig ¶ added in v0.41.0
type SpeechModelConfig struct {
Provider string
APIKey string
DefaultOptions speech.Options
BaseURL string
HTTPClient *http.Client
// Call must fit in memory; Stream retains incremental delivery. Zero uses
// speech.DefaultMaxAudioBytes, and a negative limit is invalid.
MaxResponseBytes int64
}
func (SpeechModelConfig) Validate ¶ added in v0.41.0
func (s SpeechModelConfig) Validate() error
type TextReasoningConfig ¶ added in v0.57.0
type TextReasoningConfig struct {
Fields []TextReasoningField
Replay TextReasoningReplay
}
Fields names the provider's documented alternatives. Field identity survives accumulation so historical reasoning is replayed under the key that issued it.
func (TextReasoningConfig) Validate ¶ added in v0.57.0
func (t TextReasoningConfig) Validate() error
type TextReasoningField ¶
type TextReasoningField string
const ( TextReasoningContent TextReasoningField = reasoningContentField TextReasoning TextReasoningField = reasoningField )
type TextReasoningReplay ¶ added in v0.57.0
type TextReasoningReplay uint8
const ( TextReasoningReplayNever TextReasoningReplay = iota TextReasoningReplayAlways TextReasoningReplayWithToolCalls )
type TokenLimitField ¶
type TokenLimitField string
TokenLimitField identifies the provider's wire field for Core's neutral Options.MaxOutputTokens value. OpenAI-compatible APIs are not uniform here: legacy-compatible providers accept max_tokens while newer protocols use max_completion_tokens.
const ( // TokenLimitMaxTokens selects the legacy-compatible max_tokens field. TokenLimitMaxTokens TokenLimitField = "max_tokens" // TokenLimitMaxCompletionTokens selects max_completion_tokens. TokenLimitMaxCompletionTokens TokenLimitField = "max_completion_tokens" )
func (TokenLimitField) String ¶
func (t TokenLimitField) String() string
func (TokenLimitField) Valid ¶
func (t TokenLimitField) Valid() bool
type TranscriptionModel ¶ added in v0.41.0
type TranscriptionModel struct {
// contains filtered or unexported fields
}
func NewTranscriptionModel ¶ added in v0.41.0
func NewTranscriptionModel(ctx context.Context, config TranscriptionModelConfig) (*TranscriptionModel, error)
func (*TranscriptionModel) Call ¶ added in v0.41.0
func (t *TranscriptionModel) Call(ctx context.Context, req *transcription.Request) (*transcription.Response, error)
type TranscriptionModelConfig ¶ added in v0.41.0
type TranscriptionModelConfig struct {
Provider string
APIKey string
DefaultOptions transcription.Options
BaseURL string
HTTPClient *http.Client
}
func (TranscriptionModelConfig) Validate ¶ added in v0.41.0
func (t TranscriptionModelConfig) Validate() error
Source Files
¶
- api.go
- audio_file.go
- audio_request_projection.go
- audio_translation.go
- chat_completions.go
- chat_completions_dialect.go
- chat_completions_output_format.go
- chat_completions_reasoning_details.go
- chat_completions_request.go
- chat_completions_request_options.go
- chat_completions_response.go
- chat_completions_stream.go
- chat_completions_text_reasoning.go
- constants.go
- doc.go
- embedding.go
- error.go
- image.go
- media_location.go
- model_list_response.go
- moderation.go
- option_validation.go
- output_schema.go
- reasoning_effort.go
- request_fields.go
- response_index.go
- response_wire.go
- responses.go
- responses_dialect.go
- responses_media.go
- responses_reasoning.go
- responses_request.go
- responses_request_field.go
- responses_request_projection.go
- responses_response.go
- responses_stream.go
- responses_stream_content.go
- responses_stream_reasoning.go
- responses_stream_tools.go
- speech.go
- stream_identity.go
- transcription.go
- usage.go