adapters

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const DynamicProviderEnvVar = "GRAYCODE_ROUTER_ALLOW_DYNAMIC_PROVIDERS"

DynamicProviderEnvVar is the opt-in env var that allows graycode-router to auto-register an OpenAI-compatible provider from OPENAI_API_BASE / OPENAI_BASE_URL when an unknown provider name is requested.

View Source
const GeminiSharedParserEnvVar = geminiSharedParserEnvVar

GeminiSharedParserEnvVar controls the shared SSE parser compatibility switch.

Variables

View Source
var (
	OpenAICompat = OpenAICompatConfig{
		SupportsStore: true, SupportsDeveloperRole: true,
		SupportsReasoningEffort: true, SupportsUsageInStreaming: true,
		MaxTokensField: "max_completion_tokens",
	}
	GrokCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	OpenRouterCompat = OpenAICompatConfig{
		ThinkingFormat: "openrouter", MaxTokensField: "max_tokens",
		SupportsUsageInStreaming: true,
	}
	GeminiCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens", SupportsUsageInStreaming: true,
	}
	ZAICompat = OpenAICompatConfig{
		ThinkingFormat: "zai", MaxTokensField: "max_tokens",
		SupportsUsageInStreaming: true,
	}
	CanopyWaveCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	OpenGatewayCompat = OpenAICompatConfig{
		MaxTokensField:           "max_tokens",
		SupportsUsageInStreaming: true,
	}
	OllamaCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	OpenCodeGoCompat = OpenAICompatConfig{
		MaxTokensField:           "max_tokens",
		SupportsUsageInStreaming: true,
		ThinkingFormat:           "openrouter",
	}
	PoolsideCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	GroqCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	ClinePassCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	KimiCompat = OpenAICompatConfig{
		MaxTokensField:         "max_tokens",
		SupportsCacheRole:      true,
		ThinkingFormat:         "kimi",
		DefaultDisableThinking: true,
	}
	XiaomiCompat = OpenAICompatConfig{
		MaxTokensField:         "max_completion_tokens",
		ThinkingFormat:         "xiaomi",
		DefaultDisableThinking: true,
	}
	AzureCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	BedrockCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	VertexCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
	// AgnesCompat: OpenAI-compatible; pre-authorizes max token cost, so omit max_tokens.
	AgnesCompat = OpenAICompatConfig{
		OmitMaxTokens:  true,
		ThinkingFormat: "agnes",
	}
	// LongCatCompat: OpenAI-compatible; enables thinking by default, so disable it.
	LongCatCompat = OpenAICompatConfig{
		MaxTokensField:         "max_tokens",
		ThinkingFormat:         "longcat",
		DefaultDisableThinking: true,
	}
	// MiniMaxCompat: OpenAI-compatible; enables thinking by default, so disable it.
	MiniMaxCompat = OpenAICompatConfig{
		MaxTokensField:         "max_tokens",
		ThinkingFormat:         "minimax",
		DefaultDisableThinking: true,
	}
	// DeepSeekCompat: OpenAI-compatible with usage in streaming.
	// DeepSeek requires the assistant's reasoning_content to be passed back whenever
	// that turn performed a tool call (HTTP 400 otherwise), so we forward it.
	// Enables thinking by default, so disable it.
	DeepSeekCompat = OpenAICompatConfig{
		MaxTokensField:            "max_tokens",
		SupportsUsageInStreaming:  true,
		RequiresReasoningPassback: true,
		ThinkingFormat:            "deepseek",
		DefaultDisableThinking:    true,
	}
	ConcentrateCompat = OpenAICompatConfig{
		MaxTokensField:           "max_tokens",
		SupportsUsageInStreaming: true,
	}
	StepFunCompat = OpenAICompatConfig{
		MaxTokensField: "max_tokens",
	}
)

Per-provider compat configs.

View Source
var CoreProviders, OpenAICompatibleProviders = staticProviderMaps()

CoreProviders and OpenAICompatibleProviders are derived from the canonical catalog registry. Dynamic providers are added only to the compatible map.

View Source
var DynamicMu sync.RWMutex

DynamicMu protects the OpenAICompatibleProviders map from concurrent access.

Functions

func AWSCanonicalURI

func AWSCanonicalURI(uri string) string

AWSCanonicalURI returns the canonical URI used by SigV4.

func AWSSigningKey

func AWSSigningKey(secret, dateStamp, region, service string) []byte

AWSSigningKey derives a SigV4 signing key from explicit inputs.

func AnthropicBaseFromOpenAIV1

func AnthropicBaseFromOpenAIV1(openAIBase string) string

AnthropicBaseFromOpenAIV1 strips a trailing /v1 from an OpenAI-compatible base URL. OpenCode Go Anthropic models share the host without the /v1 suffix.

func AudioFormatToMediaType

func AudioFormatToMediaType(format string) string

func BuildAnthropicCachedRequest

func BuildAnthropicCachedRequest(messages []core.GraycodeRouterMessage, model string, maxTokens int, temperature *float64, stream bool, tools []AnthropicTool,
	thinking *AnthropicThinking, toolChoice *AnthropicToolChoice, topP *float64, topK *int, stopSequences []string,
) map[string]interface{}

BuildAnthropicCachedRequest creates an Anthropic request with cache breakpoints.

func BuildAnthropicMessages

func BuildAnthropicMessages(messages []core.GraycodeRouterMessage) ([]map[string]interface{}, string)

func CanonicalAWSHeaders

func CanonicalAWSHeaders(headers http.Header) (string, string)

CanonicalAWSHeaders canonicalizes a header set for SigV4.

func ConvertToAnthropicTools

func ConvertToAnthropicTools(tools []core.GraycodeRouterTool) []anthropicTool

func DetectProvider

func DetectProvider() string

DetectProvider detects the active provider from the credential store (not process env).

func DynamicProviderEnabled

func DynamicProviderEnabled() bool

DynamicProviderEnabled reports whether callers may auto-register an OpenAI-compatible provider from OPENAI_API_BASE / OPENAI_BASE_URL when an unknown provider name is requested.

func FreezeRegistry

func FreezeRegistry()

FreezeRegistry prevents further provider registrations.

func OACompatUnsupportedError

func OACompatUnsupportedError(err error) bool

OACompatUnsupportedError reports whether an error indicates OA-compat is unsupported.

func OpenAIBaseFallbackURL

func OpenAIBaseFallbackURL() string

OpenAIBaseFallbackURL returns the OPENAI_API_BASE or OPENAI_BASE_URL env var.

func OpenAIToolChoice

func OpenAIToolChoice(tc *core.ToolChoiceOption) interface{}

OpenAIToolChoice converts the public tool-choice contract to wire form.

func ParseAnthropicResponse

func ParseAnthropicResponse(ar anthropicResponse, requestID, orgID string) *core.GraycodeRouterResponse

ParseAnthropicResponse converts a parsed Anthropic Messages API response into an core.GraycodeRouterResponse. Shared by Anthropic, Bedrock, and Vertex clients (all three receive the same wire format).

Content blocks are extracted per type:

  • "text" → Content (concatenated)
  • "thinking" → Thinking (concatenated)
  • "redacted_thinking" → skipped silently (safety-sensitive reasoning)
  • "tool_use" → appended to ToolCalls with parsed Arguments

requestID is required. orgID is the Anthropic-Organization-Id response header (Anthropic-specific; Bedrock and Vertex pass "").

func ProcessGeminiStream

func ProcessGeminiStream(ctx context.Context, events <-chan core.SSEEvent, logger *slog.Logger) <-chan core.GraycodeRouterStreamEvent

ProcessGeminiStream normalizes decoded Gemini SSE events.

func RegisterDynamicProvider

func RegisterDynamicProvider(name, baseURL, envKey string) error

RegisterDynamicProvider adds a user-defined OpenAI-compatible provider at runtime.

func ResolveEnvSecret

func ResolveEnvSecret(envKey string) string

ResolveEnvSecret looks up an environment variable via the credential store with a bounded timeout.

func ResolveProviderModelEnvOverride

func ResolveProviderModelEnvOverride(provider string) string

ResolveProviderModelEnvOverride resolves the model env override for a provider.

func Sha256Hex

func Sha256Hex(data []byte) string

Sha256Hex returns a lowercase SHA-256 digest.

func ThinkingForBudget

func ThinkingForBudget(budget int) *anthropicThinking

ThinkingForBudget builds the wire-level extended-thinking configuration.

Types

type AgnesClient

type AgnesClient struct {
	// contains filtered or unexported fields
}

AgnesClient uses the OpenAI-compatible Agnes AI endpoint. Official docs expose an OpenAI-compatible API only.

func NewAgnesClient

func NewAgnesClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *AgnesClient

NewAgnesClient builds an Agnes AI provider client. openAIBase is typically "https://apihub.agnes-ai.com/v1".

func (*AgnesClient) Chat

func (*AgnesClient) Name

func (c *AgnesClient) Name() string

func (*AgnesClient) Ping

func (c *AgnesClient) Ping(ctx context.Context) error

func (*AgnesClient) StreamChat

func (c *AgnesClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type AnthropicClient

type AnthropicClient struct {
	// contains filtered or unexported fields
}

AnthropicClient implements core.Provider for the Anthropic Messages API.

func NewAnthropicClient

func NewAnthropicClient(apiKey, baseURL string, opts ...core.ClientOption) *AnthropicClient

NewAnthropicClient creates a configured Anthropic client.

func (*AnthropicClient) BaseURL

func (c *AnthropicClient) BaseURL() string

func (*AnthropicClient) BuildAnthropicRequest

func (c *AnthropicClient) BuildAnthropicRequest(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions, stream bool) (*http.Request, []byte, error)

BuildAnthropicRequest constructs a complete Anthropic Messages request.

func (*AnthropicClient) Chat

Anthropic structured output is sent through output_config.format. A schema-less json_object request is rejected instead of being silently ignored because Anthropic requires a JSON schema.

func (*AnthropicClient) CountTokens

CountTokens counts the number of tokens in a message without generating a response. Uses the same request format as Chat but hits the /v1/messages/count_tokens endpoint. The request body includes model, messages, system, and tools (but not max_tokens or stream).

func (*AnthropicClient) DefaultMaxTokens

func (c *AnthropicClient) DefaultMaxTokens() int

func (*AnthropicClient) DefaultModel

func (c *AnthropicClient) DefaultModel() string

func (*AnthropicClient) DefaultTemperature

func (c *AnthropicClient) DefaultTemperature() *float64

func (*AnthropicClient) Guardrails

func (c *AnthropicClient) Guardrails() *core.Guardrails

func (*AnthropicClient) HTTPClient

func (c *AnthropicClient) HTTPClient() *http.Client

func (*AnthropicClient) Logger

func (c *AnthropicClient) Logger() *slog.Logger

func (*AnthropicClient) Name

func (c *AnthropicClient) Name() string

Name returns the provider name.

func (*AnthropicClient) Ping

func (c *AnthropicClient) Ping(ctx context.Context) error

Ping checks connectivity to the Anthropic API using a lightweight GET request.

func (*AnthropicClient) Retry

func (c *AnthropicClient) Retry() core.RetryConfig

func (*AnthropicClient) SetAPIKey

func (c *AnthropicClient) SetAPIKey(key string)

SetAPIKey sets the API key.

func (*AnthropicClient) SetBaseURL

func (c *AnthropicClient) SetBaseURL(url string)

SetBaseURL sets the base URL.

func (*AnthropicClient) SetDefaultMaxTokens

func (c *AnthropicClient) SetDefaultMaxTokens(n int)

SetDefaultMaxTokens sets the default max tokens for requests.

func (*AnthropicClient) SetDefaultModel

func (c *AnthropicClient) SetDefaultModel(model string)

SetDefaultModel sets the default model for requests.

func (*AnthropicClient) SetDefaultTemperature

func (c *AnthropicClient) SetDefaultTemperature(t float64)

SetDefaultTemperature sets the default temperature for requests.

func (*AnthropicClient) SetGuardrails

func (c *AnthropicClient) SetGuardrails(g *core.Guardrails)

SetGuardrails attaches output guardrails.

func (*AnthropicClient) SetHTTPClient

func (c *AnthropicClient) SetHTTPClient(hc *http.Client)

SetHTTPClient replaces the HTTP client.

func (*AnthropicClient) SetLogger

func (c *AnthropicClient) SetLogger(l *slog.Logger)

SetLogger sets the logger.

func (*AnthropicClient) SetMimoAuth

func (c *AnthropicClient) SetMimoAuth()

SetMimoAuth switches authentication to MiMo's api-key header.

func (*AnthropicClient) SetProviderName

func (c *AnthropicClient) SetProviderName(string)

SetProviderName is a no-op: the Anthropic adapter reports a fixed provider name. Present to satisfy core.Configurable; core.WithProviderName only affects OpenAI-compatible adapters.

func (*AnthropicClient) SetRetry

func (c *AnthropicClient) SetRetry(rc core.RetryConfig)

SetRetry sets the retry configuration.

func (*AnthropicClient) SetTimeout

func (c *AnthropicClient) SetTimeout(d time.Duration)

SetTimeout sets the HTTP client timeout.

func (*AnthropicClient) StreamChat

StreamChat sends a streaming message to Anthropic.

func (*AnthropicClient) Version

func (c *AnthropicClient) Version() string

type AnthropicMetadata

type AnthropicMetadata = anthropicMetadata

type AnthropicOutputConfig

type AnthropicOutputConfig = anthropicOutputConfig

func ResolveOutputConfig

func ResolveOutputConfig(opts core.ChatOptions) *AnthropicOutputConfig

type AnthropicOutputFormat

type AnthropicOutputFormat = anthropicOutputFormat

type AnthropicRequest

type AnthropicRequest = anthropicRequest

type AnthropicResponse

type AnthropicResponse = anthropicResponse

type AnthropicThinking

type AnthropicThinking = anthropicThinking

func ResolveThinking

func ResolveThinking(opts core.ChatOptions) *AnthropicThinking

type AnthropicTool

type AnthropicTool = anthropicTool

type AnthropicToolChoice

type AnthropicToolChoice = anthropicToolChoice

func ResolveToolChoice

func ResolveToolChoice(tc *core.ToolChoiceOption) *AnthropicToolChoice

type AzureClient

type AzureClient struct {
	// contains filtered or unexported fields
}

func NewAzureClient

func NewAzureClient(apiKey, endpoint, apiVersion string) *AzureClient

func (*AzureClient) APIVersion

func (c *AzureClient) APIVersion() string

APIVersion returns the API version.

func (*AzureClient) Chat

func (*AzureClient) Endpoint

func (c *AzureClient) Endpoint() string

Endpoint returns the base endpoint.

func (*AzureClient) Name

func (c *AzureClient) Name() string

func (*AzureClient) Ping

func (c *AzureClient) Ping(ctx context.Context) error

func (*AzureClient) SetHTTPClient

func (c *AzureClient) SetHTTPClient(hc *http.Client)

SetHTTPClient replaces the transport used for Azure requests.

func (*AzureClient) SetRetry

func (c *AzureClient) SetRetry(rc core.RetryConfig)

SetRetry configures provider retry behavior.

func (*AzureClient) StreamChat

func (c *AzureClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type BedrockClient

type BedrockClient struct {
	// contains filtered or unexported fields
}

func NewBedrockClient

func NewBedrockClient(accessKeyID, secretAccessKey, sessionToken, region string) *BedrockClient

func (*BedrockClient) BuildBody

func (c *BedrockClient) BuildBody(messages []core.GraycodeRouterMessage, opts core.ChatOptions) ([]byte, error)

BuildBody creates the Anthropic-compatible Bedrock request payload.

func (*BedrockClient) Chat

func (*BedrockClient) HTTPClient

func (c *BedrockClient) HTTPClient() *http.Client

HTTPClient returns the underlying HTTP client.

func (*BedrockClient) ModelURL

func (c *BedrockClient) ModelURL(model string) string

ModelURL returns the signed model URL for Bedrock.

func (*BedrockClient) Name

func (c *BedrockClient) Name() string

func (*BedrockClient) Ping

func (c *BedrockClient) Ping(ctx context.Context) error

func (*BedrockClient) Region

func (c *BedrockClient) Region() string

Region returns the AWS region.

func (*BedrockClient) Retry

func (c *BedrockClient) Retry() core.RetryConfig

Retry returns the retry configuration.

func (*BedrockClient) SetHTTPClient

func (c *BedrockClient) SetHTTPClient(hc *http.Client)

func (*BedrockClient) SetRetry

func (c *BedrockClient) SetRetry(rc core.RetryConfig)

func (*BedrockClient) Sign

func (c *BedrockClient) Sign(req *http.Request, body []byte, now time.Time) error

Sign applies AWS SigV4 headers to a Bedrock request.

func (*BedrockClient) StreamChat

func (c *BedrockClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

func (*BedrockClient) String

func (c *BedrockClient) String() string

String returns a safe string representation of the Bedrock client. Sensitive fields (secret access key) are masked to prevent accidental exposure in logs.

type CanopyWaveClient

type CanopyWaveClient struct {
	// contains filtered or unexported fields
}

CanopyWaveClient uses the OpenAI-compatible CanopyWave endpoint.

func NewCanopyWaveClient

func NewCanopyWaveClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *CanopyWaveClient

NewCanopyWaveClient builds a CanopyWave provider client. openAIBase is typically "https://inference.canopywave.io/v1".

func (*CanopyWaveClient) Chat

func (*CanopyWaveClient) Name

func (c *CanopyWaveClient) Name() string

func (*CanopyWaveClient) Ping

func (c *CanopyWaveClient) Ping(ctx context.Context) error

func (*CanopyWaveClient) StreamChat

type ChatProtocol

type ChatProtocol int

ChatProtocol selects which existing graycode-router client handles a gateway request.

const (
	// ChatProtocolCompletions routes via OpenAIClient (POST /v1/chat/completions).
	ChatProtocolCompletions ChatProtocol = iota
	// ChatProtocolMessages routes via AnthropicClient (POST /v1/messages).
	ChatProtocolMessages
)

type ClinePassClient

type ClinePassClient struct {
	// contains filtered or unexported fields
}

ClinePassClient uses the OpenAI-compatible ClinePass endpoint.

func NewClinePassClient

func NewClinePassClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *ClinePassClient

NewClinePassClient builds a ClinePass provider client. openAIBase is typically "https://api.cline.bot/api/v1".

func (*ClinePassClient) Chat

func (*ClinePassClient) Name

func (c *ClinePassClient) Name() string

func (*ClinePassClient) Ping

func (c *ClinePassClient) Ping(ctx context.Context) error

func (*ClinePassClient) StreamChat

type ConcentrateResponsesClient

type ConcentrateResponsesClient struct {
	// contains filtered or unexported fields
}

ConcentrateResponsesClient uses the Concentrate Responses API (the production-ready API per Concentrate docs). This is the recommended adapter for Concentrate AI.

The Responses API uses /v1/responses endpoint with a unified format that works across all models (OpenAI, Anthropic, Google, etc.).

func NewConcentrateResponsesClient

func NewConcentrateResponsesClient(apiKey, baseURL string, opts ...core.ClientOption) *ConcentrateResponsesClient

NewConcentrateResponsesClient builds a Concentrate AI provider client using the Responses API. baseURL is typically "https://api.concentrate.ai/v1".

func (*ConcentrateResponsesClient) BaseURL

func (c *ConcentrateResponsesClient) BaseURL() string

BaseURL implements core.Configurable.

func (*ConcentrateResponsesClient) Chat

Chat implements core.Provider using the Responses API.

func (*ConcentrateResponsesClient) DefaultMaxTokens

func (c *ConcentrateResponsesClient) DefaultMaxTokens() int

DefaultMaxTokens implements core.Configurable.

func (*ConcentrateResponsesClient) DefaultModel

func (c *ConcentrateResponsesClient) DefaultModel() string

DefaultModel implements core.Configurable.

func (*ConcentrateResponsesClient) DefaultTemperature

func (c *ConcentrateResponsesClient) DefaultTemperature() *float64

DefaultTemperature implements core.Configurable.

func (*ConcentrateResponsesClient) Guardrails

func (c *ConcentrateResponsesClient) Guardrails() *core.Guardrails

Guardrails implements core.Configurable.

func (*ConcentrateResponsesClient) HTTPClient

func (c *ConcentrateResponsesClient) HTTPClient() *http.Client

HTTPClient implements core.Configurable.

func (*ConcentrateResponsesClient) Logger

func (c *ConcentrateResponsesClient) Logger() *slog.Logger

Logger implements core.Configurable.

func (*ConcentrateResponsesClient) Name

func (*ConcentrateResponsesClient) Ping

Ping checks the health of the Concentrate API.

func (*ConcentrateResponsesClient) Retry

Retry implements core.Configurable.

func (*ConcentrateResponsesClient) SetAPIKey

func (c *ConcentrateResponsesClient) SetAPIKey(key string)

SetAPIKey implements core.Configurable.

func (*ConcentrateResponsesClient) SetBaseURL

func (c *ConcentrateResponsesClient) SetBaseURL(url string)

SetBaseURL implements core.Configurable.

func (*ConcentrateResponsesClient) SetDefaultMaxTokens

func (c *ConcentrateResponsesClient) SetDefaultMaxTokens(n int)

SetDefaultMaxTokens implements core.Configurable.

func (*ConcentrateResponsesClient) SetDefaultModel

func (c *ConcentrateResponsesClient) SetDefaultModel(model string)

SetDefaultModel implements core.Configurable.

func (*ConcentrateResponsesClient) SetDefaultTemperature

func (c *ConcentrateResponsesClient) SetDefaultTemperature(t float64)

SetDefaultTemperature implements core.Configurable.

func (*ConcentrateResponsesClient) SetGuardrails

func (c *ConcentrateResponsesClient) SetGuardrails(g *core.Guardrails)

SetGuardrails implements core.Configurable.

func (*ConcentrateResponsesClient) SetHTTPClient

func (c *ConcentrateResponsesClient) SetHTTPClient(hc *http.Client)

SetHTTPClient implements core.Configurable.

func (*ConcentrateResponsesClient) SetLogger

func (c *ConcentrateResponsesClient) SetLogger(l *slog.Logger)

SetLogger implements core.Configurable.

func (*ConcentrateResponsesClient) SetMimoAuth

func (c *ConcentrateResponsesClient) SetMimoAuth()

SetMimoAuth implements core.Configurable.

func (*ConcentrateResponsesClient) SetProviderName

func (c *ConcentrateResponsesClient) SetProviderName(string)

SetProviderName implements core.Configurable.

func (*ConcentrateResponsesClient) SetRetry

SetRetry implements core.Configurable.

func (*ConcentrateResponsesClient) SetTimeout

func (c *ConcentrateResponsesClient) SetTimeout(d time.Duration)

SetTimeout implements core.Configurable.

func (*ConcentrateResponsesClient) StreamChat

StreamChat implements core.Provider using the Responses API with SSE streaming.

func (*ConcentrateResponsesClient) Version

func (c *ConcentrateResponsesClient) Version() string

Version implements core.Configurable.

type DeepSeekClient

type DeepSeekClient struct {
	// contains filtered or unexported fields
}

DeepSeekClient uses the OpenAI-compatible DeepSeek endpoint.

func NewDeepSeekClient

func NewDeepSeekClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *DeepSeekClient

NewDeepSeekClient builds a DeepSeek provider client. openAIBase is typically "https://api.deepseek.com"

func (*DeepSeekClient) Chat

func (*DeepSeekClient) Name

func (c *DeepSeekClient) Name() string

func (*DeepSeekClient) Ping

func (c *DeepSeekClient) Ping(ctx context.Context) error

func (*DeepSeekClient) StreamChat

type GeminiClient

type GeminiClient struct {
	// contains filtered or unexported fields
}

GeminiClient implements core.Provider for the Google Gemini API.

func NewGeminiClient

func NewGeminiClient(apiKey, baseURL string) *GeminiClient

func (*GeminiClient) Chat

func (*GeminiClient) HTTPClient

func (c *GeminiClient) HTTPClient() *http.Client

HTTPClient returns the configured transport client.

func (*GeminiClient) Name

func (c *GeminiClient) Name() string

func (*GeminiClient) Ping

func (c *GeminiClient) Ping(ctx context.Context) error

func (*GeminiClient) Retry

func (c *GeminiClient) Retry() core.RetryConfig

Retry returns the configured retry policy.

func (*GeminiClient) StreamChat

func (c *GeminiClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type GeminiOpenAIClient

type GeminiOpenAIClient struct {
	// contains filtered or unexported fields
}

GeminiOpenAIClient uses the OpenAI-compatible Gemini endpoint (generativelanguage.googleapis.com openai compatibility layer). Distinct from the native GeminiClient which uses generateContent.

func NewGeminiOpenAIClient

func NewGeminiOpenAIClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *GeminiOpenAIClient

NewGeminiOpenAIClient builds a Gemini provider client over the OpenAI-compatible endpoint. openAIBase is typically "https://generativelanguage.googleapis.com/v1beta/openai".

func (*GeminiOpenAIClient) Chat

func (*GeminiOpenAIClient) Name

func (c *GeminiOpenAIClient) Name() string

func (*GeminiOpenAIClient) Ping

func (c *GeminiOpenAIClient) Ping(ctx context.Context) error

func (*GeminiOpenAIClient) StreamChat

type GrokClient

type GrokClient struct {
	// contains filtered or unexported fields
}

GrokClient uses the OpenAI-compatible xAI (Grok) endpoint.

func NewGrokClient

func NewGrokClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *GrokClient

NewGrokClient builds an xAI (Grok) provider client. openAIBase is typically "https://api.x.ai/v1".

func (*GrokClient) Chat

func (*GrokClient) Name

func (c *GrokClient) Name() string

func (*GrokClient) Ping

func (c *GrokClient) Ping(ctx context.Context) error

func (*GrokClient) StreamChat

func (c *GrokClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type GroqClient

type GroqClient struct {
	// contains filtered or unexported fields
}

GroqClient uses the OpenAI-compatible Groq endpoint.

func NewGroqClient

func NewGroqClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *GroqClient

NewGroqClient builds a Groq provider client. openAIBase is typically "https://api.groq.com/openai/v1".

func (*GroqClient) Chat

func (*GroqClient) Name

func (c *GroqClient) Name() string

func (*GroqClient) Ping

func (c *GroqClient) Ping(ctx context.Context) error

func (*GroqClient) StreamChat

func (c *GroqClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type KimiClient

type KimiClient struct {
	// contains filtered or unexported fields
}

KimiClient uses the OpenAI-compatible Kimi (Moonshot) endpoint.

func NewKimiClient

func NewKimiClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *KimiClient

NewKimiClient builds a Kimi (Moonshot) provider client. openAIBase is typically "https://api.moonshot.ai/v1".

func (*KimiClient) Chat

func (*KimiClient) Name

func (c *KimiClient) Name() string

func (*KimiClient) Ping

func (c *KimiClient) Ping(ctx context.Context) error

func (*KimiClient) StreamChat

func (c *KimiClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type LongCatClient

type LongCatClient struct {
	// contains filtered or unexported fields
}

LongCatClient uses the OpenAI-compatible LongCat endpoint first, with Anthropic-compatible fallback on retriable errors. Both protocols are documented at https://longcat.chat/platform/docs/api/chat and https://longcat.chat/platform/docs/api/messages.

func NewLongCatClient

func NewLongCatClient(apiKey, openAIBase, anthropicBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *LongCatClient

NewLongCatClient builds a LongCat dual-protocol client. openAIBase should be "https://api.longcat.chat/openai/v1". anthropicBase should be "https://api.longcat.chat/anthropic". The same apiKey is used for both sides.

func (*LongCatClient) Chat

func (*LongCatClient) Name

func (c *LongCatClient) Name() string

func (*LongCatClient) Ping

func (c *LongCatClient) Ping(ctx context.Context) error

func (*LongCatClient) StreamChat

func (c *LongCatClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type MiMoClient

type MiMoClient struct {
	// contains filtered or unexported fields
}

MiMoClient uses the OpenAI-compatible MiMo endpoint.

func NewMiMoClient

func NewMiMoClient(apiKey, openAIBase string, compat *OpenAICompatConfig, providerID string, opts ...core.ClientOption) *MiMoClient

NewMiMoClient builds a MiMo provider client (payg or token_plan gateway).

func (*MiMoClient) Chat

func (*MiMoClient) Name

func (c *MiMoClient) Name() string

func (*MiMoClient) Ping

func (c *MiMoClient) Ping(ctx context.Context) error

func (*MiMoClient) ProviderID

func (c *MiMoClient) ProviderID() string

ProviderID reports the configured MiMo gateway identity.

func (*MiMoClient) StreamChat

func (c *MiMoClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type MiniMaxClient

type MiniMaxClient struct {
	// contains filtered or unexported fields
}

MiniMaxClient uses the OpenAI-compatible MiniMax endpoint.

func NewMiniMaxClient

func NewMiniMaxClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *MiniMaxClient

NewMiniMaxClient builds a MiniMax provider client. openAIBase is typically "https://api.minimax.io/v1".

func (*MiniMaxClient) Chat

func (*MiniMaxClient) Name

func (c *MiniMaxClient) Name() string

func (*MiniMaxClient) Ping

func (c *MiniMaxClient) Ping(ctx context.Context) error

func (*MiniMaxClient) StreamChat

func (c *MiniMaxClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type OllamaClient

type OllamaClient struct {
	// contains filtered or unexported fields
}

OllamaClient uses the OpenAI-compatible local Ollama endpoint.

func NewOllamaClient

func NewOllamaClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *OllamaClient

NewOllamaClient builds an Ollama provider client. openAIBase is typically "http://localhost:11434/v1".

func (*OllamaClient) Chat

func (*OllamaClient) Name

func (c *OllamaClient) Name() string

func (*OllamaClient) Ping

func (c *OllamaClient) Ping(ctx context.Context) error

func (*OllamaClient) StreamChat

func (c *OllamaClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type OpenAIClient

type OpenAIClient struct {
	// contains filtered or unexported fields
}

func NewOpenAIClient

func NewOpenAIClient(apiKey, baseURL string, compat *OpenAICompatConfig, opts ...core.ClientOption) *OpenAIClient

NewOpenAIClient creates a configured OpenAI/compatible client.

func (*OpenAIClient) BaseURL

func (c *OpenAIClient) BaseURL() string

Inspection methods expose non-secret adapter configuration.

func (*OpenAIClient) BuildOpenAIRequest

func (c *OpenAIClient) BuildOpenAIRequest(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions, stream bool) (*http.Request, []byte, error)

BuildOpenAIRequest constructs a complete OpenAI-compatible HTTP request.

func (*OpenAIClient) Chat

Chat sends a non-streaming request.

func (*OpenAIClient) Compat

func (c *OpenAIClient) Compat() *OpenAICompatConfig

func (*OpenAIClient) CreateEmbedding

func (c *OpenAIClient) CreateEmbedding(ctx context.Context, req core.EmbeddingRequest) (*core.EmbeddingResponse, error)

CreateEmbedding sends an embedding request to the OpenAI-compatible API endpoint.

func (*OpenAIClient) DefaultMaxTokens

func (c *OpenAIClient) DefaultMaxTokens() int

func (*OpenAIClient) DefaultModel

func (c *OpenAIClient) DefaultModel() string

func (*OpenAIClient) DefaultTemperature

func (c *OpenAIClient) DefaultTemperature() *float64

func (*OpenAIClient) Guardrails

func (c *OpenAIClient) Guardrails() *core.Guardrails

func (*OpenAIClient) HTTPClient

func (c *OpenAIClient) HTTPClient() *http.Client

func (*OpenAIClient) Logger

func (c *OpenAIClient) Logger() *slog.Logger

func (*OpenAIClient) Name

func (c *OpenAIClient) Name() string

Name returns the provider name.

func (*OpenAIClient) Ping

func (c *OpenAIClient) Ping(ctx context.Context) error

Ping checks connectivity.

func (*OpenAIClient) ProviderName

func (c *OpenAIClient) ProviderName() string

func (*OpenAIClient) Retry

func (c *OpenAIClient) Retry() core.RetryConfig

func (*OpenAIClient) SetAPIKey

func (c *OpenAIClient) SetAPIKey(key string)

SetAPIKey sets the API key.

func (*OpenAIClient) SetBaseURL

func (c *OpenAIClient) SetBaseURL(url string)

SetBaseURL sets the base URL.

func (*OpenAIClient) SetDefaultMaxTokens

func (c *OpenAIClient) SetDefaultMaxTokens(n int)

SetDefaultMaxTokens sets the default max tokens for requests.

func (*OpenAIClient) SetDefaultModel

func (c *OpenAIClient) SetDefaultModel(model string)

SetDefaultModel sets the default model for requests.

func (*OpenAIClient) SetDefaultTemperature

func (c *OpenAIClient) SetDefaultTemperature(t float64)

SetDefaultTemperature sets the default temperature for requests.

func (*OpenAIClient) SetGuardrails

func (c *OpenAIClient) SetGuardrails(g *core.Guardrails)

SetGuardrails attaches output guardrails.

func (*OpenAIClient) SetHTTPClient

func (c *OpenAIClient) SetHTTPClient(hc *http.Client)

SetHTTPClient replaces the HTTP client.

func (*OpenAIClient) SetLogger

func (c *OpenAIClient) SetLogger(l *slog.Logger)

SetLogger sets the logger.

func (*OpenAIClient) SetMimoAuth

func (c *OpenAIClient) SetMimoAuth()

SetMimoAuth switches authentication to MiMo's api-key header.

func (*OpenAIClient) SetProviderName

func (c *OpenAIClient) SetProviderName(name string)

SetProviderName sets the provider name used in errors and logging.

func (*OpenAIClient) SetRetry

func (c *OpenAIClient) SetRetry(rc core.RetryConfig)

SetRetry sets the retry configuration.

func (*OpenAIClient) SetTimeout

func (c *OpenAIClient) SetTimeout(d time.Duration)

SetTimeout sets the HTTP client timeout.

func (*OpenAIClient) StreamChat

func (c *OpenAIClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

StreamChat sends a streaming request.

type OpenAICompatConfig

type OpenAICompatConfig struct {
	SupportsStore                    bool   `json:"supports_store,omitempty"`
	SupportsDeveloperRole            bool   `json:"supports_developer_role,omitempty"`
	SupportsReasoningEffort          bool   `json:"supports_reasoning_effort,omitempty"`
	SupportsUsageInStreaming         bool   `json:"supports_usage_in_streaming,omitempty"`
	SupportsStrictMode               bool   `json:"supports_strict_mode,omitempty"`
	MaxTokensField                   string `json:"max_tokens_field,omitempty"` // "max_tokens" or "max_completion_tokens"
	RequiresToolResultName           bool   `json:"requires_tool_result_name,omitempty"`
	RequiresAssistantAfterToolResult bool   `json:"requires_assistant_after_tool_result,omitempty"`
	RequiresThinkingAsText           bool   `json:"requires_thinking_as_text,omitempty"`
	ThinkingFormat                   string `json:"thinking_format,omitempty"` // "openai", "zai", "qwen", "openrouter"
	// RequiresReasoningPassback instructs buildRequestBase to forward the
	// reasoning_content captured from a prior assistant turn (core.GraycodeRouterMessage.Thinking)
	// back into the request's assistant messages. DeepSeek requires the assistant's
	// reasoning_content to be passed back whenever that turn performed a tool call,
	// otherwise the API returns HTTP 400. When no tool call happened the field is
	// ignored by the provider, so forwarding is always safe for compliant providers.
	RequiresReasoningPassback bool `json:"requires_reasoning_passback,omitempty"`
	// SupportsCacheRole enables Kimi/Moonshot context-cache injection: when
	// core.ChatOptions.KimiContextCacheID is non-empty, buildRequestBase prepends a
	// {"role":"cache","content":<id>} message per the MoonshotAI-Cookbook spec.
	SupportsCacheRole bool `json:"supports_cache_role,omitempty"`
	// OmitMaxTokens suppresses the max_tokens field so the provider applies
	// its own default. Useful for providers that pre-authorize the maximum
	// token cost (e.g. Agnes AI).
	OmitMaxTokens bool `json:"omit_max_tokens,omitempty"`
	// DefaultDisableThinking sets thinking to disabled when no thinking
	// preference is provided. Useful for providers that enable thinking
	// by default but don't support it in all configurations.
	DefaultDisableThinking bool `json:"default_disable_thinking,omitempty"`
}

OpenAICompatConfig holds provider-specific compatibility flags that control how API requests are constructed for each provider.

type OpenAIEmbeddingData

type OpenAIEmbeddingData = openaiEmbeddingData

type OpenAIEmbeddingResponse

type OpenAIEmbeddingResponse = openaiEmbeddingResponse

type OpenAIEmbeddingUsage

type OpenAIEmbeddingUsage = openaiEmbeddingUsage

type OpenAIRequest

type OpenAIRequest = openaiRequest

func BuildRequestBase

func BuildRequestBase(messages []core.GraycodeRouterMessage, opts core.ChatOptions, stream bool, compat *OpenAICompatConfig) OpenAIRequest

BuildRequestBase creates the provider-neutral OpenAI-compatible wire body.

type OpenAIResponse

type OpenAIResponse = openaiResponse

type OpenCodeGoClient

type OpenCodeGoClient struct {
	// contains filtered or unexported fields
}

OpenCodeGoClient routes OpenCode Go models through OpenAIClient and AnthropicClient per opencode.ai/docs/go, with cross-protocol fallback when the primary path returns no answer text (e.g. reasoning-only MiniMax streams).

func NewOpenCodeGoClient

func NewOpenCodeGoClient(apiKey, baseURL string, opts ...core.ClientOption) *OpenCodeGoClient

NewOpenCodeGoClient builds an OpenCode Go provider client.

func (*OpenCodeGoClient) Chat

func (*OpenCodeGoClient) Name

func (c *OpenCodeGoClient) Name() string

func (*OpenCodeGoClient) Ping

func (c *OpenCodeGoClient) Ping(ctx context.Context) error

func (*OpenCodeGoClient) StreamChat

type OpenGatewayClient

type OpenGatewayClient struct {
	// contains filtered or unexported fields
}

OpenGatewayClient uses the OpenAI-compatible OpenGateway endpoint.

func NewOpenGatewayClient

func NewOpenGatewayClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *OpenGatewayClient

NewOpenGatewayClient builds an OpenGateway provider client. openAIBase is typically "https://opengateway.gitlawb.com/v1".

func (*OpenGatewayClient) Chat

func (*OpenGatewayClient) Name

func (c *OpenGatewayClient) Name() string

func (*OpenGatewayClient) Ping

func (c *OpenGatewayClient) Ping(ctx context.Context) error

func (*OpenGatewayClient) StreamChat

type OpenRouterClient

type OpenRouterClient struct {
	// contains filtered or unexported fields
}

OpenRouterClient uses the OpenAI-compatible OpenRouter endpoint.

func NewOpenRouterClient

func NewOpenRouterClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *OpenRouterClient

NewOpenRouterClient builds an OpenRouter provider client. openAIBase is typically "https://openrouter.ai/api/v1".

func (*OpenRouterClient) Chat

func (*OpenRouterClient) Name

func (c *OpenRouterClient) Name() string

func (*OpenRouterClient) Ping

func (c *OpenRouterClient) Ping(ctx context.Context) error

func (*OpenRouterClient) StreamChat

type PoolsideClient

type PoolsideClient struct {
	// contains filtered or unexported fields
}

PoolsideClient uses Poolside's OpenAI-compatible transport and retries a reasoning-only stream once through the non-streaming endpoint. Laguna models can spend an entire streamed turn in reasoning while still returning answer content from a complete non-streaming request.

func NewPoolsideClient

func NewPoolsideClient(apiKey, baseURL string, opts ...core.ClientOption) *PoolsideClient

func (*PoolsideClient) Chat

func (*PoolsideClient) Name

func (c *PoolsideClient) Name() string

func (*PoolsideClient) Ping

func (c *PoolsideClient) Ping(ctx context.Context) error

func (*PoolsideClient) StreamChat

type ProtocolChatFallback

type ProtocolChatFallback func(primaryErr error, primaryResp *core.GraycodeRouterResponse) bool

ProtocolChatFallback decides whether to retry via the alternate protocol after the primary attempt. resp is non-nil only when primary returned err=nil.

type ProtocolRouter

type ProtocolRouter struct {
	OpenAI    *OpenAIClient
	Anthropic *AnthropicClient
}

ProtocolRouter picks between OpenAIClient and AnthropicClient for gateways that expose both APIs (OpenCode Go, MiMo). All HTTP work stays in openai.go and anthropic.go; this type only orchestrates routing and fallback.

func (ProtocolRouter) Chat

Chat sends a request via the primary protocol, optionally falling back to the alternate protocol when fallback returns true.

func (ProtocolRouter) StreamChat

StreamChat streams via the primary protocol. When FallbackOnError matches, the alternate protocol is tried immediately. When ReasoningOnlyFallback is set and the primary is /v1/messages, an empty reasoning-only stream retries via chat/completions.

type ProtocolStreamConfig

type ProtocolStreamConfig struct {
	Primary               ChatProtocol
	FallbackOnError       func(error) bool
	ReasoningOnlyFallback bool // retry alternate protocol when primary stream is reasoning-only
}

ProtocolStreamConfig controls streaming across two protocols.

type ProviderRegistryConfig

type ProviderRegistryConfig struct {
	Name              string              `json:"name"`
	Type              ProviderType        `json:"type"`
	BaseURL           string              `json:"base_url,omitempty"`
	EnvKey            string              `json:"env_key"`
	SupportsStreaming bool                `json:"supports_streaming"`
	SupportsTools     bool                `json:"supports_tools"`
	SupportsReasoning bool                `json:"supports_reasoning"`
	Compat            *OpenAICompatConfig `json:"compat,omitempty"`
}

ProviderRegistryConfig holds provider registry info.

type ProviderType

type ProviderType string

ProviderType classifies providers.

const (
	// ProviderTypeAnthropic uses the Anthropic Messages API.
	ProviderTypeAnthropic ProviderType = "anthropic"
	// ProviderTypeOpenAI uses the OpenAI Chat Completions API.
	ProviderTypeOpenAI ProviderType = "openai"
	// ProviderTypeOpenAICompatible uses OpenAI-compatible APIs with custom base URLs.
	ProviderTypeOpenAICompatible ProviderType = "openai-compatible"
	// ProviderTypeAzure uses Azure OpenAI.
	ProviderTypeAzure ProviderType = "azure"
	// ProviderTypeBedrock uses AWS Bedrock.
	ProviderTypeBedrock ProviderType = "bedrock"
	// ProviderTypeVertex uses Google Vertex AI.
	ProviderTypeVertex ProviderType = "vertex"
)

type StepFunClient

type StepFunClient struct {
	// contains filtered or unexported fields
}

StepFunClient uses the OpenAI-compatible StepFun endpoint. Official docs: https://platform.stepfun.com/docs/en/api-reference

func NewStepFunClient

func NewStepFunClient(apiKey, openAIBase string, compat *OpenAICompatConfig, opts ...core.ClientOption) *StepFunClient

NewStepFunClient builds a StepFun provider client. openAIBase is typically "https://api.stepfun.ai/v1".

func (*StepFunClient) Chat

func (*StepFunClient) Name

func (c *StepFunClient) Name() string

func (*StepFunClient) Ping

func (c *StepFunClient) Ping(ctx context.Context) error

func (*StepFunClient) StreamChat

func (c *StepFunClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type TokenCountResult

type TokenCountResult struct {
	InputTokens int `json:"input_tokens"`
}

TokenCountResult holds the result of a token count request.

type VertexClient

type VertexClient struct {
	// contains filtered or unexported fields
}

func NewVertexClient

func NewVertexClient(projectID, region, token string) *VertexClient

func (*VertexClient) BaseURL

func (c *VertexClient) BaseURL() string

BaseURL returns the base URL for Vertex API requests.

func (*VertexClient) BuildBody

func (c *VertexClient) BuildBody(messages []core.GraycodeRouterMessage, opts core.ChatOptions, stream bool) ([]byte, error)

BuildBody constructs the request body for Vertex API calls.

func (*VertexClient) Chat

func (*VertexClient) HTTPClient

func (c *VertexClient) HTTPClient() *http.Client

HTTPClient returns the configured transport client.

func (*VertexClient) Name

func (c *VertexClient) Name() string

func (*VertexClient) Ping

func (c *VertexClient) Ping(ctx context.Context) error

func (*VertexClient) ProjectID

func (c *VertexClient) ProjectID() string

ProjectID returns the configured Google Cloud project identifier.

func (*VertexClient) Region

func (c *VertexClient) Region() string

Region returns the configured Google Cloud region.

func (*VertexClient) SetHTTPClient

func (c *VertexClient) SetHTTPClient(hc *http.Client)

SetHTTPClient replaces the transport used for Vertex requests.

func (*VertexClient) SetRetry

func (c *VertexClient) SetRetry(rc core.RetryConfig)

SetRetry configures provider retry behavior.

func (*VertexClient) StreamChat

func (c *VertexClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

type ZAIClient

type ZAIClient struct {
	// contains filtered or unexported fields
}

ZAIClient uses the OpenAI-compatible endpoint (paas/v4 or coding/paas/v4) first, with Anthropic-compatible fallback (/api/anthropic) on retriable errors. This provides proper separation for General vs Coding Plan while giving both protocol surfaces (exactly as Xiaomi MiMo does for its plans).

func NewZAIClient

func NewZAIClient(apiKey, openAIBase, anthropicBase string, compat *OpenAICompatConfig, providerID string, opts ...core.ClientOption) *ZAIClient

NewZAIClient builds a Z.AI dual-protocol client for a given plan/region gateway. openAIBase should be the resolved general or coding paas base. anthropicBase should be the resolved /api/anthropic (global or cn). The same apiKey is used for both sides; the plan subscription attached to the key controls quota/billing when using the coding path.

func (*ZAIClient) Chat

func (*ZAIClient) Name

func (c *ZAIClient) Name() string

func (*ZAIClient) Ping

func (c *ZAIClient) Ping(ctx context.Context) error

func (*ZAIClient) StreamChat

func (c *ZAIClient) StreamChat(ctx context.Context, messages []core.GraycodeRouterMessage, opts core.ChatOptions) (*core.StreamResult, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL