xai.go

 1// Package xai provides a Fantasy provider for the xAI API.
 2package xai
 3
 4import (
 5	"charm.land/fantasy"
 6	"charm.land/fantasy/providers/openaicompat"
 7)
 8
 9const (
10	// Name is the provider identifier for xAI.
11	Name = "xai"
12	// BaseURL is the default xAI API base URL.
13	BaseURL = "https://api.x.ai/v1"
14)
15
16// Option configures the xAI provider via OpenAI-compatible options.
17type Option = openaicompat.Option
18
19var (
20	// WithBaseURL is an alias for openaicompat.WithBaseURL.
21	WithBaseURL = openaicompat.WithBaseURL
22	// WithAPIKey is an alias for openaicompat.WithAPIKey.
23	WithAPIKey = openaicompat.WithAPIKey
24	// WithHeaders is an alias for openaicompat.WithHeaders.
25	WithHeaders = openaicompat.WithHeaders
26	// WithHTTPClient is an alias for openaicompat.WithHTTPClient.
27	WithHTTPClient = openaicompat.WithHTTPClient
28	// WithSDKOptions is an alias for openaicompat.WithSDKOptions.
29	WithSDKOptions = openaicompat.WithSDKOptions
30)
31
32// New creates a new xAI provider using OpenAI-compatible transport/options.
33func New(opts ...Option) (fantasy.Provider, error) {
34	options := []Option{
35		openaicompat.WithName(Name),
36		WithBaseURL(BaseURL),
37	}
38	options = append(options, opts...)
39	return openaicompat.New(options...)
40}