Documentation
¶
Overview ¶
Package client manages upstream API client connections.
Package client manages upstream API client connections.
Index ¶
- Constants
- func IsAnthropicModel(modelID string) bool
- func IsBedrock(model config.ModelConfig) bool
- func IsZen(model config.ModelConfig) bool
- func Provider(model config.ModelConfig) string
- type APIError
- type EndpointType
- type OpenCodeClient
- func (c *OpenCodeClient) ChatCompletion(ctx context.Context, modelID string, req *types.ChatCompletionRequest, ...) (*http.Response, error)
- func (c *OpenCodeClient) ChatCompletionNonStreaming(ctx context.Context, modelID string, req *types.ChatCompletionRequest, ...) (*types.ChatCompletionResponse, error)
- func (c *OpenCodeClient) GeminiCompletion(ctx context.Context, modelID string, req *types.GeminiRequest, ...) (*http.Response, error)
- func (c *OpenCodeClient) GeminiCompletionNonStreaming(ctx context.Context, modelID string, req *types.GeminiRequest, ...) (*types.GeminiResponse, error)
- func (c *OpenCodeClient) GetGeminiStreamingBody(ctx context.Context, modelID string, req *types.GeminiRequest, ...) (io.ReadCloser, error)
- func (c *OpenCodeClient) GetResponsesStreamingBody(ctx context.Context, modelID string, req *types.ResponsesRequest, ...) (io.ReadCloser, error)
- func (c *OpenCodeClient) GetStreamingBody(ctx context.Context, modelID string, req *types.ChatCompletionRequest, ...) (io.ReadCloser, error)
- func (c *OpenCodeClient) RequestTimeout(model config.ModelConfig) time.Duration
- func (c *OpenCodeClient) ResponsesCompletion(ctx context.Context, modelID string, req *types.ResponsesRequest, ...) (*http.Response, error)
- func (c *OpenCodeClient) ResponsesCompletionNonStreaming(ctx context.Context, modelID string, req *types.ResponsesRequest, ...) (*types.ResponsesResponse, error)
- func (c *OpenCodeClient) SendAnthropicRequest(ctx context.Context, body []byte, stream bool, modelConfig config.ModelConfig) (*http.Response, error)
- func (c *OpenCodeClient) StreamIdleTimeout(modelConfig config.ModelConfig) time.Duration
- func (c *OpenCodeClient) StreamingTimeout(model config.ModelConfig) time.Duration
Constants ¶
const ( ProviderOpenCodeGo = "opencode-go" ProviderOpenCodeZen = "opencode-zen" ProviderAWSBedrock = "aws-bedrock" )
Variables ¶
This section is empty.
Functions ¶
func IsAnthropicModel ¶
IsAnthropicModel returns true if the model requires the Anthropic endpoint. Most Go provider models use the Chat Completions transform path for broader compatibility (tool format, message roles, etc.). Exceptions are models whose upstream backends don't support the OpenAI Chat Completions format and only accept Anthropic Messages format.
Only Zen models use the raw Anthropic endpoint via ClassifyEndpoint.
func IsBedrock ¶ added in v0.3.9
func IsBedrock(model config.ModelConfig) bool
IsBedrock returns true if the model uses the AWS Bedrock provider.
func IsZen ¶
func IsZen(model config.ModelConfig) bool
IsZen returns true if the model uses the OpenCode Zen provider.
func Provider ¶
func Provider(model config.ModelConfig) string
Provider returns the provider string for a model config. Defaults to ProviderOpenCodeGo if empty.
Types ¶
type APIError ¶ added in v0.3.4
APIError represents an HTTP API error returned by an upstream provider. Callers should use errors.As to check for this type and inspect StatusCode for classification (4xx non-retryable, 5xx retryable, etc.).
type EndpointType ¶
type EndpointType int
EndpointType determines which Zen endpoint format to use.
const ( EndpointChatCompletions EndpointType = iota // /v1/chat/completions (OpenAI-compatible) EndpointAnthropic // /v1/messages (Anthropic format) EndpointResponses // /v1/responses (OpenAI native) EndpointGemini // /v1/models/{id} (Google Gemini) )
func ClassifyEndpoint ¶
func ClassifyEndpoint(modelID string) EndpointType
ClassifyEndpoint determines the endpoint type for a model on Zen. This is Zen-specific: minimax models use chat completions on Zen (they use Anthropic only on the Go provider).
type OpenCodeClient ¶
type OpenCodeClient struct {
// contains filtered or unexported fields
}
OpenCodeClient handles communication with OpenCode Go and Zen APIs.
func NewOpenCodeClient ¶
func NewOpenCodeClient(atomic *config.AtomicConfig) *OpenCodeClient
NewOpenCodeClient creates a new OpenCode client.
func (*OpenCodeClient) ChatCompletion ¶
func (c *OpenCodeClient) ChatCompletion( ctx context.Context, modelID string, req *types.ChatCompletionRequest, modelConfig config.ModelConfig, ) (*http.Response, error)
ChatCompletion sends a chat completion request.
func (*OpenCodeClient) ChatCompletionNonStreaming ¶
func (c *OpenCodeClient) ChatCompletionNonStreaming( ctx context.Context, modelID string, req *types.ChatCompletionRequest, modelConfig config.ModelConfig, ) (*types.ChatCompletionResponse, error)
ChatCompletionNonStreaming sends a non-streaming request and returns the full parsed response.
func (*OpenCodeClient) GeminiCompletion ¶
func (c *OpenCodeClient) GeminiCompletion( ctx context.Context, modelID string, req *types.GeminiRequest, modelConfig config.ModelConfig, ) (*http.Response, error)
GeminiCompletion sends a request to the Gemini endpoint.
func (*OpenCodeClient) GeminiCompletionNonStreaming ¶
func (c *OpenCodeClient) GeminiCompletionNonStreaming( ctx context.Context, modelID string, req *types.GeminiRequest, modelConfig config.ModelConfig, ) (*types.GeminiResponse, error)
GeminiCompletionNonStreaming sends a non-streaming Gemini request.
func (*OpenCodeClient) GetGeminiStreamingBody ¶
func (c *OpenCodeClient) GetGeminiStreamingBody( ctx context.Context, modelID string, req *types.GeminiRequest, modelConfig config.ModelConfig, ) (io.ReadCloser, error)
GetGeminiStreamingBody returns the response body for Gemini streaming.
func (*OpenCodeClient) GetResponsesStreamingBody ¶
func (c *OpenCodeClient) GetResponsesStreamingBody( ctx context.Context, modelID string, req *types.ResponsesRequest, modelConfig config.ModelConfig, ) (io.ReadCloser, error)
GetResponsesStreamingBody returns the response body for Responses streaming.
func (*OpenCodeClient) GetStreamingBody ¶
func (c *OpenCodeClient) GetStreamingBody( ctx context.Context, modelID string, req *types.ChatCompletionRequest, modelConfig config.ModelConfig, ) (io.ReadCloser, error)
GetStreamingBody returns the response body for streaming consumption.
func (*OpenCodeClient) RequestTimeout ¶ added in v0.3.4
func (c *OpenCodeClient) RequestTimeout(model config.ModelConfig) time.Duration
RequestTimeout returns the provider timeout for a non-streaming attempt.
func (*OpenCodeClient) ResponsesCompletion ¶
func (c *OpenCodeClient) ResponsesCompletion( ctx context.Context, modelID string, req *types.ResponsesRequest, modelConfig config.ModelConfig, ) (*http.Response, error)
ResponsesCompletion sends a request to the OpenAI Responses endpoint.
func (*OpenCodeClient) ResponsesCompletionNonStreaming ¶
func (c *OpenCodeClient) ResponsesCompletionNonStreaming( ctx context.Context, modelID string, req *types.ResponsesRequest, modelConfig config.ModelConfig, ) (*types.ResponsesResponse, error)
ResponsesCompletionNonStreaming sends a non-streaming Responses request.
func (*OpenCodeClient) SendAnthropicRequest ¶
func (c *OpenCodeClient) SendAnthropicRequest( ctx context.Context, body []byte, stream bool, modelConfig config.ModelConfig, ) (*http.Response, error)
SendAnthropicRequest sends a raw Anthropic-format request.
func (*OpenCodeClient) StreamIdleTimeout ¶
func (c *OpenCodeClient) StreamIdleTimeout(modelConfig config.ModelConfig) time.Duration
StreamIdleTimeout returns the maximum gap between bytes on an active stream for a model. The stream lives as long as data keeps flowing; only an idle period longer than this value is treated as a stuck connection and aborted. Go provider models use OpenCodeGo.StreamTimeoutMs; Zen models use OpenCodeZen.StreamTimeoutMs; Bedrock models use AWSBedrock.StreamTimeoutMs. Falls back to 5 minutes if the config is unavailable or the value is zero.
func (*OpenCodeClient) StreamingTimeout ¶ added in v0.3.4
func (c *OpenCodeClient) StreamingTimeout(model config.ModelConfig) time.Duration
StreamingTimeout returns the provider timeout for a streaming attempt.