Documentation
¶
Overview ¶
Package xai provides the main client for interacting with xAI services.
Package xai provides the main client for interacting with xAI services.
Index ¶
- type Client
- func (c *Client) Auth() *auth.Client
- func (c *Client) Chat() xaiv1.ChatClient
- func (c *Client) Close() error
- func (c *Client) CloseWithContext(ctx context.Context) error
- func (c *Client) Collections() *collections.Client
- func (c *Client) Config() *Config
- func (c *Client) CreatedAt() time.Time
- func (c *Client) Deferred() *deferred.Client
- func (c *Client) Documents() *documents.Client
- func (c *Client) Embed() *embed.Client
- func (c *Client) EnsureGRPCConnection() error
- func (c *Client) Files() *files.Client
- func (c *Client) GRPCConnection() *grpc.ClientConn
- func (c *Client) GetHealthStatus() HealthStatus
- func (c *Client) HealthCheck(_ context.Context) error
- func (c *Client) Images() *image.Client
- func (c *Client) IsClosed() bool
- func (c *Client) Metadata() *metadata.SDKMetadata
- func (c *Client) Models() *models.Client
- func (c *Client) NewChatRequest(model string, opts ...chat.RequestOption) *chat.Request
- func (c *Client) NewContext(ctx context.Context) context.Context
- func (c *Client) NewContextWithCancel(ctx context.Context) (context.Context, context.CancelFunc)
- func (c *Client) NewContextWithDeadline(ctx context.Context, deadline time.Time) (context.Context, context.CancelFunc)
- func (c *Client) NewContextWithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- func (c *Client) Sample() *sample.Client
- func (c *Client) String() string
- func (c *Client) Tokenizer() *tokenizer.Client
- func (c *Client) WithAPIKey(apiKey string) *Client
- func (c *Client) WithTimeout(timeout time.Duration) *Client
- type Config
- func (c *Config) CreateGRPCDialOptions() ([]grpc.DialOption, error)
- func (c *Config) GRPCAddress() string
- func (c *Config) HTTPAddress() string
- func (c *Config) LoadFromEnvironment()
- func (c *Config) String() string
- func (c *Config) ToSDKMetadata() *metadata.SDKMetadata
- func (c *Config) Validate() error
- func (c *Config) WithAPIKey(apiKey string) *Config
- func (c *Config) WithEnableTelemetry(enable bool) *Config
- func (c *Config) WithEnvironment(env string) *Config
- func (c *Config) WithHost(host string) *Config
- func (c *Config) WithInsecure(insecure bool) *Config
- func (c *Config) WithMaxBackoff(backoff time.Duration) *Config
- func (c *Config) WithMaxRetries(maxRetries int) *Config
- func (c *Config) WithRetryBackoff(backoff time.Duration) *Config
- func (c *Config) WithSkipVerify(skipVerify bool) *Config
- func (c *Config) WithTLSConfig(tlsConfig *tls.Config) *Config
- func (c *Config) WithTimeout(timeout time.Duration) *Config
- func (c *Config) WithUserAgent(userAgent string) *Config
- type HealthStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents the main xAI SDK client.
func NewClientFromEnvironment ¶
NewClientFromEnvironment creates a new client loading configuration from environment variables.
func NewClientWithAPIKey ¶
NewClientWithAPIKey creates a new client with the given API key and default configuration.
func (*Client) Chat ¶
func (c *Client) Chat() xaiv1.ChatClient
Chat returns the chat service client.
func (*Client) CloseWithContext ¶
CloseWithContext closes the client with a context for cancellation.
func (*Client) Collections ¶
func (c *Client) Collections() *collections.Client
Collections returns the collections service client.
func (*Client) EnsureGRPCConnection ¶
EnsureGRPCConnection ensures that the gRPC connection is healthy and reconnect if needed.
func (*Client) GRPCConnection ¶
func (c *Client) GRPCConnection() *grpc.ClientConn
GRPCConnection returns the underlying gRPC connection. This should be used sparingly and callers should not close this connection.
func (*Client) GetHealthStatus ¶
func (c *Client) GetHealthStatus() HealthStatus
GetHealthStatus returns the current health status of the client.
func (*Client) HealthCheck ¶
HealthCheck performs a health check on the client connection.
func (*Client) Metadata ¶
func (c *Client) Metadata() *metadata.SDKMetadata
Metadata returns the client's SDK metadata.
func (*Client) NewChatRequest ¶
NewChatRequest creates a new chat request with the specified model.
func (*Client) NewContext ¶
NewContext creates a new context with the client's configuration and metadata.
func (*Client) NewContextWithCancel ¶
NewContextWithCancel creates a new context with a cancel function.
func (*Client) NewContextWithDeadline ¶
func (c *Client) NewContextWithDeadline(ctx context.Context, deadline time.Time) (context.Context, context.CancelFunc)
NewContextWithDeadline creates a new context with a deadline.
func (*Client) NewContextWithTimeout ¶
func (c *Client) NewContextWithTimeout(ctx context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
NewContextWithTimeout creates a new context with a specific timeout.
func (*Client) Sample ¶ added in v0.3.0
Sample returns the sample/completion service client (legacy).
func (*Client) WithAPIKey ¶
WithAPIKey creates a new client with a different API key.
type Config ¶
type Config struct {
// APIKey is the xAI API key for authentication.
APIKey string `json:"api_key"`
// Host is the xAI API host (default: api.x.ai).
Host string `json:"host"`
// GRPCPort is the gRPC port (default: 443).
GRPCPort string `json:"grpc_port"`
// HTTPHost is the HTTP API host (default: api.x.ai).
HTTPHost string `json:"http_host"`
// HTTPPort is the HTTP API port (default: 80).
HTTPPort string `json:"http_port"`
// Timeout is the default request timeout (default: 30s).
Timeout time.Duration `json:"timeout"`
// ConnectTimeout is the connection timeout (default: 10s).
ConnectTimeout time.Duration `json:"connect_timeout"`
// KeepAliveTimeout is the keep-alive timeout (default: 20s).
KeepAliveTimeout time.Duration `json:"keep_alive_timeout"`
// StreamTimeout is the streaming timeout (default: 300s).
StreamTimeout time.Duration `json:"stream_timeout"`
// Insecure controls whether to use TLS (default: false).
// WARNING: Setting this to true disables TLS encryption entirely.
// Only use in local development or testing environments. Never use in production.
Insecure bool `json:"insecure"`
// SkipVerify controls whether to skip TLS certificate verification (default: false).
// WARNING: Setting this to true disables certificate validation, making connections
// vulnerable to man-in-the-middle attacks. Only use in local development or testing
// environments with self-signed certificates. Never use in production.
SkipVerify bool `json:"skip_verify"`
// MaxRetries is the maximum number of retries (default: 3).
MaxRetries int `json:"max_retries"`
// RetryBackoff is the retry backoff duration (default: 1s).
RetryBackoff time.Duration `json:"retry_backoff"`
// MaxBackoff is the maximum backoff duration (default: 60s).
MaxBackoff time.Duration `json:"max_backoff"`
// Environment is the deployment environment (default: production).
Environment string `json:"environment"`
// UserAgent is the user agent string (default: xai-sdk-go/version).
UserAgent string `json:"user_agent"`
// EnableTelemetry controls whether to enable telemetry (default: true).
EnableTelemetry bool `json:"enable_telemetry"`
// CustomTLSConfig allows providing a custom TLS configuration.
CustomTLSConfig *tls.Config `json:"-"`
}
Config represents the client configuration.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with default values.
func NewConfig ¶
func NewConfig() *Config
NewConfig creates a new Config with default values and applies environment variable overrides.
func NewConfigWithAPIKey ¶
NewConfigWithAPIKey creates a new Config with the provided API key.
func (*Config) CreateGRPCDialOptions ¶
func (c *Config) CreateGRPCDialOptions() ([]grpc.DialOption, error)
CreateGRPCDialOptions creates gRPC dial options based on the configuration.
func (*Config) GRPCAddress ¶
GRPCAddress returns the gRPC address for this configuration.
func (*Config) HTTPAddress ¶
HTTPAddress returns the HTTP address for this configuration.
func (*Config) LoadFromEnvironment ¶
func (c *Config) LoadFromEnvironment()
LoadFromEnvironment loads configuration from environment variables.
func (*Config) String ¶
String returns a string representation of the config (without sensitive data).
func (*Config) ToSDKMetadata ¶
func (c *Config) ToSDKMetadata() *metadata.SDKMetadata
ToSDKMetadata converts the config to SDK metadata.
func (*Config) WithAPIKey ¶
WithAPIKey sets the API key.
func (*Config) WithEnableTelemetry ¶
WithEnableTelemetry sets the telemetry enabled flag.
func (*Config) WithEnvironment ¶
WithEnvironment sets the environment.
func (*Config) WithInsecure ¶
WithInsecure sets the insecure flag.
func (*Config) WithMaxBackoff ¶
WithMaxBackoff sets the maximum backoff duration.
func (*Config) WithMaxRetries ¶
WithMaxRetries sets the maximum number of retries.
func (*Config) WithRetryBackoff ¶
WithRetryBackoff sets the retry backoff duration.
func (*Config) WithSkipVerify ¶
WithSkipVerify sets the skip verify flag.
func (*Config) WithTLSConfig ¶
WithTLSConfig sets a custom TLS configuration.
func (*Config) WithTimeout ¶
WithTimeout sets the request timeout.
func (*Config) WithUserAgent ¶
WithUserAgent sets the user agent.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package auth provides a client for the xAI Auth API.
|
Package auth provides a client for the xAI Auth API. |
|
Package chat provides chat completion functionality for the xAI SDK.
|
Package chat provides chat completion functionality for the xAI SDK. |
|
Package collections provides a client for the xAI Collections API.
|
Package collections provides a client for the xAI Collections API. |
|
Package deferred provides a client for the xAI Deferred Completions API.
|
Package deferred provides a client for the xAI Deferred Completions API. |
|
Package documents provides a client for the xAI Document Search API.
|
Package documents provides a client for the xAI Document Search API. |
|
Package embed provides client functionality for the xAI Embeddings API.
|
Package embed provides client functionality for the xAI Embeddings API. |
|
Package files provides a client for the xAI Files API.
|
Package files provides a client for the xAI Files API. |
|
Package image provides a client for the xAI Image Generation API.
|
Package image provides a client for the xAI Image Generation API. |
|
internal
|
|
|
auth
Package auth provides authentication interceptors for gRPC requests.
|
Package auth provides authentication interceptors for gRPC requests. |
|
constants
Package constants provides default constants used throughout the xAI SDK.
|
Package constants provides default constants used throughout the xAI SDK. |
|
errors
Package errors provides error types and utilities for the xAI SDK.
|
Package errors provides error types and utilities for the xAI SDK. |
|
grpcutil
Package grpcutil provides gRPC utility functions and interceptors.
|
Package grpcutil provides gRPC utility functions and interceptors. |
|
metadata
Package metadata provides utilities for working with gRPC metadata and headers.
|
Package metadata provides utilities for working with gRPC metadata and headers. |
|
rest
Package rest provides a REST client for xAI APIs.
|
Package rest provides a REST client for xAI APIs. |
|
version
Package version provides version information for the xAI SDK.
|
Package version provides version information for the xAI SDK. |
|
Package models provides model information functionality for xAI SDK.
|
Package models provides model information functionality for xAI SDK. |
|
Package sample provides a client for the xAI Sample/Completion API (legacy).
|
Package sample provides a client for the xAI Sample/Completion API (legacy). |
|
Package tokenizer provides a client for the xAI Tokenization API.
|
Package tokenizer provides a client for the xAI Tokenization API. |