openaicred

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CredentialsFromConfig

func CredentialsFromConfig(apiKey string, apiKeys []string) ([]credpool.Credential, error)

CredentialsFromConfig builds credpool.Credential entries for one backend instance. Ordering matches credpool.BackendKeySecrets (api_key first, then api_keys; deduplicated).

func DefaultSDKMaxRetries

func DefaultSDKMaxRetries(v *int) *int

DefaultSDKMaxRetries returns v if non-nil, or a pointer to 0. Retry policy above the HTTP round trip lives in credential-rotation loops and core failover; disabling hidden SDK retries prevents differing attempt economics (Requirements 10, 12).

func ExecuteWithCredentialPool

func ExecuteWithCredentialPool(
	ctx context.Context,
	providerID string,
	pool *credpool.Pool,
	rateLimitFallback time.Duration,
	fn func(ctx context.Context, cred credpool.Credential) (lipapi.ManagedEventStream, error),
) (lipapi.ManagedEventStream, error)

ExecuteWithCredentialPool executes fn within the credential pool acquire/cooldown/retry loop. On FailureAuthInvalid or FailureRateLimited, the credential is marked and the loop retries with another available credential. On FailureRetryable, lipapi.RecoverablePreOutputError is returned. When pool is nil, fn is called once with an empty credential.

func NewClient

func NewClient(baseURL, apiSecret string, httpClient *http.Client, maxRetries *int) openai.Client

NewClient builds an openai-go client for the given base URL and API secret. httpClient and maxRetries may be nil / omitted for SDK defaults.

func NewClientWithOptions

func NewClientWithOptions(baseURL, apiSecret string, httpClient *http.Client, maxRetries *int, extraOpts []option.RequestOption) openai.Client

NewClientWithOptions builds an openai-go client with additional per-client request options. extraOpts are appended after base URL, API key, HTTP client, and max retries. An empty apiSecret omits Authorization entirely (compatible-mode no-auth); non-empty secrets including native dummy credentials still set option.WithAPIKey.

func NewPool

func NewPool(apiKey string, apiKeys []string) (*credpool.Pool, error)

NewPool builds a credpool.Pool from backend config fields.

func NewPoolFromCredentials

func NewPoolFromCredentials(apiKey string, apiKeys []string, credentials []credpool.Credential) (*credpool.Pool, error)

Types

type FailureKind

type FailureKind int

FailureKind classifies an OpenAI HTTP API error for credential-pool handling.

const (
	// FailureNone means the error is not a classified OpenAI API HTTP failure.
	FailureNone FailureKind = iota
	FailureRateLimited
	FailureAuthInvalid
	// FailureRetryable means a transient upstream (5xx, 408) or transport failure
	// (timeout, connection reset/refused) worth a pre-output failover.
	FailureRetryable
)

func ClassifyHTTPResponse

func ClassifyHTTPResponse(resp *http.Response) (kind FailureKind, retryAfter string)

ClassifyHTTPResponse classifies an *http.Response for credential-pool handling.

func ClassifyHTTPStatus

func ClassifyHTTPStatus(statusCode int, header http.Header) (kind FailureKind, retryAfter string)

ClassifyHTTPStatus classifies an HTTP status code and optional headers for credential-pool handling.

func ClassifyOpenAIAPIError

func ClassifyOpenAIAPIError(err error) (kind FailureKind, retryAfter string)

ClassifyOpenAIAPIError inspects *openai.Error or HTTPStatusError (including wrapped). On rate limit it returns the Retry-After header value when present (may be empty). Transport-level failures are classified via transporterr.IsRetryable.

type HTTPStatusError

type HTTPStatusError interface {
	error
	HTTPStatusCode() int
	HTTPHeader() http.Header
}

HTTPStatusError represents an error carrying an HTTP status code and response headers.

Jump to

Keyboard shortcuts

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