Documentation
¶
Overview ¶
Package vercel provides an implementation of the fantasy AI SDK for Vercel AI Gateway.
Package vercel provides an implementation of the fantasy AI SDK for Vercel AI Gateway.
Index ¶
- Constants
- func New(opts ...Option) (fantasy.Provider, error)
- func NewProviderOptions(opts *ProviderOptions) fantasy.ProviderOptions
- type BYOKCredential
- type BYOKOptions
- type GatewayProviderOptions
- type Option
- func WithAPIKey(apiKey string) Option
- func WithBaseURL(url string) Option
- func WithHTTPClient(client option.HTTPClient) Option
- func WithHeaders(headers map[string]string) Option
- func WithName(name string) Option
- func WithObjectMode(om fantasy.ObjectMode) Option
- func WithSDKOptions(opts ...option.RequestOption) Option
- func WithUserAgent(ua string) Option
- type ProviderMetadata
- type ProviderOptions
- type ReasoningData
- type ReasoningDetail
- type ReasoningEffort
- type ReasoningOptions
Constants ¶
const ( TypeProviderOptions = Name + ".options" TypeProviderMetadata = Name + ".metadata" )
Global type identifiers for Vercel-specific provider data.
const ( // DefaultURL is the default URL for the Vercel AI Gateway API. DefaultURL = "https://ai-gateway.vercel.sh/v1" // Name is the name of the Vercel provider. Name = "vercel" )
Variables ¶
This section is empty.
Functions ¶
func NewProviderOptions ¶
func NewProviderOptions(opts *ProviderOptions) fantasy.ProviderOptions
NewProviderOptions creates new provider options for Vercel.
Types ¶
type BYOKCredential ¶
type BYOKCredential struct {
APIKey string `json:"apiKey,omitempty"`
}
BYOKCredential represents a single provider credential for BYOK.
type BYOKOptions ¶
type BYOKOptions struct {
Anthropic map[string][]BYOKCredential `json:"anthropic,omitempty"`
OpenAI map[string][]BYOKCredential `json:"openai,omitempty"`
Vertex map[string][]BYOKCredential `json:"vertex,omitempty"`
Bedrock map[string][]BYOKCredential `json:"bedrock,omitempty"`
}
BYOKOptions represents Bring Your Own Key options for Vercel AI Gateway.
type GatewayProviderOptions ¶
type GatewayProviderOptions struct {
// Order is the list of provider slugs to try in order (e.g. ["vertex", "anthropic"]).
Order []string `json:"order,omitempty"`
// Models is the list of fallback models to try if the primary model fails.
Models []string `json:"models,omitempty"`
// ZeroDataRetention control whether zero data retention is enforced.
ZeroDataRetention *bool `json:"zeroDataRetention,omitempty"`
}
GatewayProviderOptions represents provider routing preferences for Vercel AI Gateway.
type Option ¶
type Option = func(*options)
Option defines a function that configures Vercel provider options.
func WithAPIKey ¶
WithAPIKey sets the API key for the Vercel provider.
func WithBaseURL ¶
WithBaseURL sets the base URL for the Vercel provider.
func WithHTTPClient ¶
func WithHTTPClient(client option.HTTPClient) Option
WithHTTPClient sets the HTTP client for the Vercel provider.
func WithHeaders ¶
WithHeaders sets the headers for the Vercel provider.
func WithObjectMode ¶
func WithObjectMode(om fantasy.ObjectMode) Option
WithObjectMode sets the object generation mode for the Vercel provider. Supported modes: ObjectModeTool, ObjectModeText. ObjectModeAuto and ObjectModeJSON are automatically converted to ObjectModeTool since Vercel AI Gateway doesn't support native JSON mode.
func WithSDKOptions ¶
func WithSDKOptions(opts ...option.RequestOption) Option
WithSDKOptions sets the SDK options for the Vercel provider.
func WithUserAgent ¶ added in v0.12.0
WithUserAgent sets an explicit User-Agent header, overriding the default and any value set via WithHeaders.
type ProviderMetadata ¶
type ProviderMetadata struct {
Provider string `json:"provider,omitempty"`
}
ProviderMetadata represents metadata from Vercel AI Gateway provider.
func (ProviderMetadata) MarshalJSON ¶
func (m ProviderMetadata) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling with type info for ProviderMetadata.
func (*ProviderMetadata) Options ¶
func (*ProviderMetadata) Options()
Options implements the ProviderOptionsData interface for ProviderMetadata.
func (*ProviderMetadata) UnmarshalJSON ¶
func (m *ProviderMetadata) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling with type info for ProviderMetadata.
type ProviderOptions ¶
type ProviderOptions struct {
// Reasoning configuration for models that support extended thinking.
Reasoning *ReasoningOptions `json:"reasoning,omitempty"`
// ProviderOptions for gateway routing preferences.
ProviderOptions *GatewayProviderOptions `json:"providerOptions,omitempty"`
// BYOK for request-scoped provider credentials.
BYOK *BYOKOptions `json:"byok,omitempty"`
// User is a unique identifier representing your end-user.
User *string `json:"user,omitempty"`
// LogitBias modifies the likelihood of specified tokens appearing in the completion.
LogitBias map[string]int64 `json:"logit_bias,omitempty"`
// LogProbs returns the log probabilities of the tokens.
LogProbs *bool `json:"logprobs,omitempty"`
// TopLogProbs is the number of top log probabilities to return.
TopLogProbs *int64 `json:"top_logprobs,omitempty"`
// ParallelToolCalls enables parallel function calling during tool use.
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"`
// ExtraBody for additional request body fields.
ExtraBody map[string]any `json:"extra_body,omitempty"`
}
ProviderOptions represents additional options for Vercel AI Gateway provider.
func ParseOptions ¶
func ParseOptions(data map[string]any) (*ProviderOptions, error)
ParseOptions parses provider options from a map for Vercel.
func (ProviderOptions) MarshalJSON ¶
func (o ProviderOptions) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling with type info for ProviderOptions.
func (*ProviderOptions) Options ¶
func (*ProviderOptions) Options()
Options implements the ProviderOptionsData interface for ProviderOptions.
func (*ProviderOptions) UnmarshalJSON ¶
func (o *ProviderOptions) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling with type info for ProviderOptions.
type ReasoningData ¶
type ReasoningData struct {
Reasoning string `json:"reasoning,omitempty"`
ReasoningDetails []ReasoningDetail `json:"reasoning_details,omitempty"`
}
ReasoningData represents reasoning data from Vercel AI Gateway response.
type ReasoningDetail ¶
type ReasoningDetail struct {
ID string `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"`
Format string `json:"format,omitempty"`
Summary string `json:"summary,omitempty"`
Signature string `json:"signature,omitempty"`
Index int `json:"index"`
}
ReasoningDetail represents a reasoning detail from Vercel AI Gateway.
type ReasoningEffort ¶
type ReasoningEffort string
ReasoningEffort represents the reasoning effort level for Vercel AI Gateway.
const ( // ReasoningEffortNone disables reasoning. ReasoningEffortNone ReasoningEffort = "none" // ReasoningEffortMinimal represents minimal reasoning effort (~10% of max_tokens). ReasoningEffortMinimal ReasoningEffort = "minimal" // ReasoningEffortLow represents low reasoning effort (~20% of max_tokens). ReasoningEffortLow ReasoningEffort = "low" // ReasoningEffortMedium represents medium reasoning effort (~50% of max_tokens). ReasoningEffortMedium ReasoningEffort = "medium" // ReasoningEffortHigh represents high reasoning effort (~80% of max_tokens). ReasoningEffortHigh ReasoningEffort = "high" // ReasoningEffortXHigh represents extra high reasoning effort (~95% of max_tokens). ReasoningEffortXHigh ReasoningEffort = "xhigh" )
func ReasoningEffortOption ¶
func ReasoningEffortOption(e ReasoningEffort) *ReasoningEffort
ReasoningEffortOption creates a pointer to a ReasoningEffort value.
type ReasoningOptions ¶
type ReasoningOptions struct {
// Enabled enables reasoning output. When true, the model will provide its reasoning process.
Enabled *bool `json:"enabled,omitempty"`
// MaxTokens is the maximum number of tokens to allocate for reasoning.
// Cannot be used with Effort.
MaxTokens *int64 `json:"max_tokens,omitempty"`
// Effort controls reasoning effort level.
// Mutually exclusive with MaxTokens.
Effort *ReasoningEffort `json:"effort,omitempty"`
// Exclude excludes reasoning content from the response but still generates it internally.
Exclude *bool `json:"exclude,omitempty"`
}
ReasoningOptions represents reasoning configuration for Vercel AI Gateway.