providerping

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package providerping does the minimum possible real check of whether a configured provider account is actually reachable and authorized right now — a "list models" call (the same convention nearly every one of these APIs supports), never a real completion request. It exists so the CLI's accounts screen can show a real, current status instead of just "a key is set" — a key can be present and still be rate-limited, revoked, or pointed at a provider having an outage, and a chat request is the only way to actually find that out before this existed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListModels added in v0.4.0

func ListModels(ctx context.Context, baseURL, apiKey string) ([]string, error)

ListModels queries baseURL's OpenAI-compatible "/models" endpoint and returns the model IDs it advertises, sorted — the exact same request Ping's "openai-compat" branch already makes for a connectivity check, just reading the body instead of discarding it. Lets a caller (the CLI's custom-provider form) offer a real, currently-available model to pick from instead of asking the user to type one by hand and find out later, at the first real turn, whether they got it right. apiKey may be empty for a no-auth local/LAN server, matching buildPingRequest's own "openai-compat" convention.

Types

type Result

type Result struct {
	Status  Status
	Latency time.Duration
	// Detail is a short, human-readable explanation — empty for a clean
	// StatusOK, set for anything else ("no quota (429)", "invalid
	// key", "high latency", ...).
	Detail string
}

Result is one provider's current, real status.

func Ping

func Ping(ctx context.Context, kind, baseURL, apiKey string) Result

Ping makes one minimal request against kind's API (anthropic, gemini, openai-compat, or openai-responses) using apiKey, and classifies the result. baseURL, if empty, uses each kind's public default — the same convention internal/provider's adapters already use. Every kind here has exactly one real auth shape (see internal/oauthflow/anthropic.go's doc comment for why an Anthropic account connected via browser login still ends up with a plain, permanent API key rather than needing a second auth mode here).

type Status

type Status int

Status is a ping's outcome, coarse enough to map directly to a colored dot in the UI.

const (
	StatusUnknown  Status = iota // never pinged yet
	StatusOK                     // responded quickly and successfully
	StatusDegraded               // responded, but slowly, or with a soft issue
	StatusDown                   // auth failure, rate-limited, unreachable, or a server error
)

Jump to

Keyboard shortcuts

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