Documentation
¶
Overview ¶
Package openai provides OpenAI Chat Completions and Responses API clients. The selected model's APIFormat chooses the wire dialect while both codecs remain available to callers that need to target either endpoint.
Index ¶
- func New(selected model.Model, key auth.APIKey, options ...Option) (inference.Client, error)
- func NewCounter(key auth.APIKey) (contextcount.ContextCounter, error)
- type Counter
- type CounterEndpointError
- type CounterEndpointReason
- type CounterRequestError
- type CounterRequestReason
- type CounterResponseError
- type CounterResponseField
- type CounterResponseFieldError
- type CounterResponseFieldReason
- type CounterResponseReason
- type CounterStateError
- type CounterStateReason
- type Option
- type ReasoningOptions
- type ServiceTier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New constructs an OpenAI Chat Completions or Responses API client. The selected model's APIFormat chooses the bundled wire codec and route; an empty model base URL uses OpenAI's canonical v1 root.
func NewCounter ¶
func NewCounter(key auth.APIKey) (contextcount.ContextCounter, error)
NewCounter constructs an exact OpenAI Responses input-token counter.
Types ¶
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter is a separately constructed exact OpenAI Responses input-token counter. It is intentionally not embedded in the inference Client, so a normal client cannot acquire ContextCounter accidentally.
func (*Counter) CountContext ¶
func (c *Counter) CountContext(ctx context.Context, req inference.Request) (contextcount.ContextCount, error)
func (*Counter) CounterCapability ¶
func (c *Counter) CounterCapability() contextcount.CounterCapability
type CounterEndpointError ¶
type CounterEndpointError struct{ Reason CounterEndpointReason }
func (*CounterEndpointError) Error ¶
func (e *CounterEndpointError) Error() string
type CounterEndpointReason ¶
type CounterEndpointReason string
const ( CounterEndpointMalformed CounterEndpointReason = "malformed endpoint" CounterEndpointMissingHost CounterEndpointReason = "missing endpoint host" CounterEndpointCredentials CounterEndpointReason = "endpoint contains credentials" CounterEndpointUnsupportedScheme CounterEndpointReason = "unsupported endpoint scheme" CounterEndpointInsecureTransport CounterEndpointReason = "plaintext endpoint is not loopback" )
type CounterRequestError ¶
type CounterRequestError struct {
Reason CounterRequestReason
Err error
}
func (*CounterRequestError) Error ¶
func (e *CounterRequestError) Error() string
func (*CounterRequestError) Unwrap ¶
func (e *CounterRequestError) Unwrap() error
type CounterRequestReason ¶
type CounterRequestReason string
const ( CounterRequestEncodeFailed CounterRequestReason = "Responses request encoding failed" CounterRequestMalformed CounterRequestReason = "encoded request is not one JSON object" )
type CounterResponseError ¶
type CounterResponseError struct {
Reason CounterResponseReason
Err error
}
func (*CounterResponseError) Error ¶
func (e *CounterResponseError) Error() string
func (*CounterResponseError) Unwrap ¶
func (e *CounterResponseError) Unwrap() error
type CounterResponseField ¶
type CounterResponseField string
const CounterResponseFieldInputTokens CounterResponseField = "input_tokens"
type CounterResponseFieldError ¶
type CounterResponseFieldError struct {
Field CounterResponseField
Reason CounterResponseFieldReason
}
func (*CounterResponseFieldError) Error ¶
func (e *CounterResponseFieldError) Error() string
type CounterResponseFieldReason ¶
type CounterResponseFieldReason string
const CounterResponseFieldDuplicate CounterResponseFieldReason = "duplicate"
type CounterResponseReason ¶
type CounterResponseReason string
const ( CounterResponseMalformed CounterResponseReason = "malformed response" CounterResponseMissingCount CounterResponseReason = "missing input_tokens" CounterResponseInvalidCount CounterResponseReason = "invalid input_tokens" CounterResponseDuplicateField CounterResponseReason = "duplicate response field" CounterResponseBodyTooLarge CounterResponseReason = "response body too large" )
type CounterStateError ¶
type CounterStateError struct{ Reason CounterStateReason }
func (*CounterStateError) Error ¶
func (e *CounterStateError) Error() string
type CounterStateReason ¶
type CounterStateReason string
const ( CounterStateNilReceiver CounterStateReason = "nil counter" CounterStateNilContext CounterStateReason = "nil context" CounterStateMissingEndpoint CounterStateReason = "missing endpoint" CounterStateMissingAuthenticator CounterStateReason = "missing authenticator" CounterStateMissingHTTPDoer CounterStateReason = "missing HTTP doer" CounterStateInvalidTimeout CounterStateReason = "invalid timeout" )
type Option ¶
type Option func(*config)
Option customizes an OpenAI client at construction time.
func WithMetadata ¶
WithMetadata attaches OpenAI request metadata. The map is copied when the option is applied so later caller mutation cannot change a live client.
func WithPromptCacheKey ¶
WithPromptCacheKey sets the stable OpenAI prompt-cache key for requests.
func WithReasoning ¶
func WithReasoning(options ReasoningOptions) Option
WithReasoning sets the provider reasoning controls. It replaces any reasoning controls inferred from model sampling so the caller has one explicit provider-specific policy.
func WithRoundTripper ¶
func WithRoundTripper(rt http.RoundTripper) Option
WithRoundTripper installs a caller-owned verified transport.
func WithServiceTier ¶
func WithServiceTier(tier ServiceTier) Option
WithServiceTier selects the OpenAI service tier.
func WithTLSRootCAs ¶
type ReasoningOptions ¶
type ReasoningOptions struct {
Effort string `json:"effort,omitempty"`
Summary string `json:"summary,omitempty"`
}
ReasoningOptions controls OpenAI reasoning. Effort is encoded as the Responses reasoning object or Chat Completions reasoning_effort field, depending on the selected model APIFormat. Summary applies to Responses.
type ServiceTier ¶
type ServiceTier string
ServiceTier selects the OpenAI Responses processing tier.
const ( ServiceTierAuto ServiceTier = "auto" ServiceTierDefault ServiceTier = "default" ServiceTierFlex ServiceTier = "flex" ServiceTierScale ServiceTier = "scale" )
Directories
¶
| Path | Synopsis |
|---|---|
|
Package subscription exposes the OpenAI subscription registration policy boundary.
|
Package subscription exposes the OpenAI subscription registration policy boundary. |