provider

package
v0.0.0-...-81df796 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AnthropicMessagesURL   = "https://api.anthropic.com/v1/messages"
	AnthropicVersionHeader = "2023-06-01"
	ClaudeOAuthBetaHeader  = "oauth-2025-04-20"
)
View Source
const (
	ChatGPTResponsesURL        = "https://chatgpt.com/backend-api/codex/responses"
	ChatGPTResponsesCompactURL = "https://chatgpt.com/backend-api/codex/responses/compact"
	ChatGPTUsageURL            = "https://chatgpt.com/backend-api/wham/usage"
	ChatGPTAccountCheckURL     = "https://chatgpt.com/backend-api/wham/accounts/check"
)
View Source
const (
	ClaudeTokenURL = "https://console.anthropic.com/v1/oauth/token"
	ClaudeClientID = "9d1c250a-e61b-44d9-88ed-5944d1962f5e"
)
View Source
const (
	VertexAnthropicVersion   = "vertex-2023-10-16"
	VertexCloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform"
)
View Source
const ClaudeUsageURL = "https://api.anthropic.com/api/oauth/usage"
View Source
const OpenAIChatURL = "https://api.openai.com/v1/chat/completions"
View Source
const OpenAIResponsesURL = "https://api.openai.com/v1/responses"

Variables

View Source
var ClaudeTokenURLOverride string
View Source
var ClaudeUsageURLOverride string

Functions

func PrepareVertexAnthropicBody

func PrepareVertexAnthropicBody(body []byte) ([]byte, error)

Types

type AnthropicAuthMode

type AnthropicAuthMode string
const (
	AnthropicAuthAPIKey AnthropicAuthMode = "api-key"
	AnthropicAuthOAuth  AnthropicAuthMode = "oauth"
)

type AnthropicClient

type AnthropicClient struct {
	HTTPClient *http.Client
	BaseURL    string
}

func NewAnthropicClient

func NewAnthropicClient() *AnthropicClient

func (*AnthropicClient) Forward

type AnthropicForwardRequest

type AnthropicForwardRequest struct {
	Body            []byte
	APIKey          string
	AccessToken     string
	AuthMode        AnthropicAuthMode
	BaseURL         string
	Streaming       bool
	IncomingHeaders http.Header
	BetaHeader      string
}

type AnthropicVertexClient

type AnthropicVertexClient struct {
	HTTPClient  *http.Client
	BaseURL     string
	Config      VertexAnthropicConfig
	TokenSource VertexTokenSource
}

func NewAnthropicVertexClient

func NewAnthropicVertexClient(ctx context.Context, overrides ...VertexAnthropicConfig) *AnthropicVertexClient

func (*AnthropicVertexClient) Forward

func (*AnthropicVertexClient) Status

type AnthropicVertexForwardRequest

type AnthropicVertexForwardRequest struct {
	Body            []byte
	Model           string
	Streaming       bool
	IncomingHeaders http.Header
}

type ChatCompletionsClient

type ChatCompletionsClient struct {
	HTTPClient *http.Client
	BaseURL    string
}

func NewChatCompletionsClient

func NewChatCompletionsClient() *ChatCompletionsClient

func (*ChatCompletionsClient) Forward

type ChatForwardRequest

type ChatForwardRequest struct {
	Body            []byte
	APIKey          string
	BaseURL         string
	Streaming       bool
	IncomingHeaders http.Header
}

type ChatGPTClient

type ChatGPTClient struct {
	HTTPClient     *http.Client
	WhamHTTPClient *http.Client
	BaseURL        string
	CompactURL     string
	UsageURL       string
}

func NewChatGPTClient

func NewChatGPTClient() *ChatGPTClient

func (*ChatGPTClient) FetchUsage

func (c *ChatGPTClient) FetchUsage(ctx context.Context, cred Credential) (WhamUsage, error)

func (*ChatGPTClient) Forward

func (c *ChatGPTClient) Forward(ctx context.Context, req ForwardRequest) (*http.Response, error)

type ClaudeProfile

type ClaudeProfile struct {
	Email            string
	AccountID        string
	SubscriptionType string
	RateLimitTier    string
}

func GetClaudeProfile

func GetClaudeProfile(ctx context.Context, accessToken string) (ClaudeProfile, error)

type ClaudeToken

type ClaudeToken struct {
	AccessToken  string
	RefreshToken string
	ExpiresIn    int
	ExpiresAt    time.Time
}

func ExchangeClaudeCode

func ExchangeClaudeCode(ctx context.Context, code, verifier, redirectURI, state string) (ClaudeToken, error)

func RefreshClaudeToken

func RefreshClaudeToken(ctx context.Context, refreshToken string) (ClaudeToken, error)

type ClaudeUsage

type ClaudeUsage struct {
	PrimaryUsedPct   float64
	SecondaryUsedPct float64
	PrimaryResetAt   time.Time
	SecondaryResetAt time.Time
}

func GetClaudeUsage

func GetClaudeUsage(ctx context.Context, accessToken string) (ClaudeUsage, error)

type Credential

type Credential struct {
	AccessToken string
	AccountID   string
}

type ForwardRequest

type ForwardRequest struct {
	Body            []byte
	ContentType     string
	ContentEncoding string
	IncomingHeaders http.Header
	Credential      Credential
	Streaming       bool
	Compact         bool
}

type OpenAIClient

type OpenAIClient struct {
	HTTPClient *http.Client
	BaseURL    string
}

func NewOpenAIClient

func NewOpenAIClient() *OpenAIClient

func (*OpenAIClient) Forward

type OpenAIForwardRequest

type OpenAIForwardRequest struct {
	Body            []byte
	APIKey          string
	BaseURL         string
	Streaming       bool
	IncomingHeaders http.Header
}

type Token

type Token struct {
	AccessToken  string
	RefreshToken string
	IDToken      string
	ExpiresIn    int
	ExpiresAt    time.Time
}

func ExchangeOpenAICode

func ExchangeOpenAICode(ctx context.Context, code, verifier, redirectURI string) (Token, error)

func RefreshOpenAIToken

func RefreshOpenAIToken(ctx context.Context, refreshToken string) (Token, error)

type TokenError

type TokenError struct {
	Status int
	Body   string
}

func (*TokenError) Error

func (e *TokenError) Error() string

type VertexAnthropicConfig

type VertexAnthropicConfig struct {
	ProjectID       string `json:"project_id"`
	Location        string `json:"location"`
	CredentialsFile string `json:"-"`
	AuthMethod      string `json:"auth_method,omitempty"`
}

func DetectVertexAnthropicConfig

func DetectVertexAnthropicConfig() VertexAnthropicConfig

type VertexAnthropicStatus

type VertexAnthropicStatus struct {
	Available  bool   `json:"available"`
	ProjectID  string `json:"project_id,omitempty"`
	Location   string `json:"location,omitempty"`
	AuthMethod string `json:"auth_method,omitempty"`
	Error      string `json:"error,omitempty"`
}

type VertexTokenSource

type VertexTokenSource interface {
	Token(ctx context.Context) (string, error)
	Method() string
}

func DefaultVertexTokenSource

func DefaultVertexTokenSource(ctx context.Context, credentialsFile ...string) (VertexTokenSource, string)

type WhamError

type WhamError struct {
	Status int
	Body   string
}

func (*WhamError) Error

func (e *WhamError) Error() string

type WhamUsage

type WhamUsage struct {
	PrimaryUsedPct   float64
	SecondaryUsedPct float64
	PrimaryResetAt   time.Time
	SecondaryResetAt time.Time
	LimitReached     bool
	PlanType         string
}

Jump to

Keyboard shortcuts

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