provider

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package provider holds the static registry of remote LLM providers nib can route to: their wire protocol, default base URL, environment variable, and (for OAuth-backed providers) the OAuth flow parameters.

The registry is the single source of truth for "which providers exist and how do I reach them". Credential storage and resolution live in package auth; wire-protocol adapters live in package llmprovider and its subpackages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Definition

type Definition struct {
	ID   string
	Name string // display name
	// Protocol is the default wire protocol for this provider's models.
	Protocol Protocol
	// BaseURL is the default API base URL (no trailing slash). Empty means
	// the OpenAI SDK default.
	BaseURL string
	// EnvVar is the environment variable that holds an API key fallback.
	EnvVar string
	// LoginKind selects the /login flow. LoginNone = env/config only.
	LoginKind LoginKind
	// CallbackPort is the loopback port the OAuth callback server binds.
	// 0 for non-OAuth providers.
	CallbackPort int
	// CallbackPath is the URL path the OAuth callback server registers.
	// Defaults to "/callback" if empty. Some providers require a specific
	// path (e.g. Google uses "/oauth2callback", OpenAI uses "/auth/callback").
	CallbackPath string
	// CallbackHost is the hostname used in the redirect URI. Defaults to
	// "localhost" if empty. Some providers require "127.0.0.1".
	CallbackHost string
	// AllowPortFallback allows the callback server to bind a random port if
	// the preferred one is busy. False for providers that validate the
	// redirect URI.
	AllowPortFallback bool

	// OAuth authorization-code flow parameters (LoginOAuthCode only).
	ClientID        string
	AuthorizeURL    string
	TokenURL        string
	Scopes          []string
	AuthorizeParams map[string]string

	// EnvClientID, if set, names an environment variable that overrides
	// ClientID at runtime. Used to avoid hardlisting OAuth client
	// credentials in source.
	EnvClientID string
	// EnvClientSecret works like EnvClientID for ClientSecret.
	EnvClientSecret string

	// DeviceURL is the device authorization endpoint (RFC 8628). Used by
	// LoginDeviceCode providers; the token endpoint is still TokenURL.
	DeviceURL string

	// TokenBodyFormat is "json" or "form". Controls how the token
	// endpoint request body is encoded. Default "json" (empty = json).
	TokenBodyFormat string
	// ClientSecret is sent in token and refresh requests if non-empty.
	// Required by providers like Google that use a confidential client.
	ClientSecret string
	// ExtraTokenHeaders are added to every token and refresh request.
	// Used for provider-specific headers like Anthropic's anthropic-beta.
	ExtraTokenHeaders map[string]string

	// IdentityURL is the endpoint called after a successful token exchange
	// to recover account info (email, account ID). Empty = skip identity
	// recovery; the credential is still valid.
	IdentityURL string
	// IdentityMethod controls how IdentityURL is called:
	// "bootstrap" — Anthropic's claude_cli/bootstrap (custom JSON shape)
	// "userinfo"  — standard OIDC userinfo endpoint (email/sub fields)
	// Empty = skip (same as IdentityURL being empty).
	IdentityMethod string
}

Definition describes one remote provider: how to reach it and how to log in.

func All

func All() []Definition

All returns every registered provider definition, in registration order. Used by /login and `nib login --list` to build the provider picker.

func Get

func Get(id string) (Definition, bool)

Get returns the Definition for provider id, or ok=false if unknown.

func Loginable

func Loginable() []Definition

Loginable returns only providers with an interactive /login flow (LoginKind != LoginNone). These are what /login's picker lists.

func (Definition) EffectiveClientID

func (d Definition) EffectiveClientID() string

EffectiveClientID returns the OAuth client ID, resolving from the environment variable named by EnvClientID when set. This keeps OAuth client credentials out of source-controlled code.

func (Definition) EffectiveClientSecret

func (d Definition) EffectiveClientSecret() string

EffectiveClientSecret returns the OAuth client secret, resolving from the environment variable named by EnvClientSecret when set.

func (Definition) NeedsBaseURL added in v0.9.1

func (d Definition) NeedsBaseURL() bool

NeedsBaseURL reports whether logging in to this provider must also collect an endpoint: it has no default base URL and nib cannot derive one (Azure, where each account has its own resource URL). OpenAI's empty BaseURL means the SDK default, so it does not count.

type LoginKind

type LoginKind string

LoginKind classifies how a provider authenticates.

const (
	// LoginNone means the provider has no interactive login flow; credentials
	// come from the environment or config only (e.g. a bare OPENAI_API_KEY,
	// or a local Ollama instance that needs no key).
	LoginNone LoginKind = ""
	// LoginAPIKey means /login prompts for an API key and stores it.
	LoginAPIKey LoginKind = "api-key"
	// LoginOAuthCode means /login runs an OAuth authorization-code flow with
	// PKCE and a loopback callback server.
	LoginOAuthCode LoginKind = "oauth-code"
	// LoginDeviceCode means /login runs an RFC 8628 device-code flow:
	// the user visits a URL and enters a code in a browser. Not yet
	// implemented — reserved for Phase 3.
	LoginDeviceCode LoginKind = "device-code"
	// LoginCopilot means /login imports an existing Copilot token from
	// the gh CLI or Copilot client config (env vars, ~/.config/github-copilot/,
	// ~/.config/gh/) and stores it. There is no OAuth or device-code flow —
	// the user authenticates via gh CLI first.
	LoginCopilot LoginKind = "copilot-token"
)

type Protocol

type Protocol string

Protocol is the wire format a provider speaks. It lives on the model, not the provider — but every built-in provider has a default protocol its models use unless overridden.

const (
	// ProtocolOpenAICompletions is the OpenAI Chat Completions API
	// (/v1/chat/completions). Any OpenAI-compatible endpoint uses this:
	// OpenAI itself, LocalAI, Ollama, vLLM, Groq, Together, OpenRouter, etc.
	ProtocolOpenAICompletions Protocol = "openai-completions"
	// ProtocolAnthropicMessages is the Anthropic Messages API (/v1/messages).
	ProtocolAnthropicMessages Protocol = "anthropic-messages"
	// ProtocolGoogleGemini is the Google Generative AI API
	// (/v1beta/models/{model}:generateContent). Used by Google AI Studio
	// and Gemini CLI.
	ProtocolGoogleGemini Protocol = "google-generative-ai"
	// ProtocolOpenAIResponses is the OpenAI Responses API
	// (/v1/responses). Used by OpenAI, GitHub Copilot, xAI OAuth,
	// Muse Code, Meta, and others.
	ProtocolOpenAIResponses Protocol = "openai-responses"
	// ProtocolOllamaChat is the Ollama native chat API (/api/chat).
	// Used by local Ollama and Ollama Cloud.
	ProtocolOllamaChat Protocol = "ollama-chat"
	// ProtocolGeminiCLI is the Google Cloud Code Assist API
	// (/v1internal:generateContent). Used by Gemini CLI. Same Gemini body
	// format as ProtocolGoogleGemini but wrapped in a Cloud Code Assist
	// envelope {project, model, request} and requiring a project ID.
	ProtocolGeminiCLI Protocol = "google-gemini-cli"
	// ProtocolGoogleVertex is the Google Vertex AI API
	// (/v1/projects/{project}/locations/{location}/publishers/google/models/{model}:generateContent).
	// Same Gemini body format as ProtocolGoogleGemini but with Vertex AI
	// URL structure and auth (API key or OAuth Bearer).
	ProtocolGoogleVertex Protocol = "google-vertex"
	// ProtocolBedrockConverse is the AWS Bedrock Converse Stream API
	// (/model/{model}/converse-stream). Uses AWS SigV4 signing and
	// binary eventstream response decoding.
	ProtocolBedrockConverse Protocol = "bedrock-converse-stream"
	// ProtocolAzureResponses is the Azure OpenAI Responses API
	// (/responses?api-version={version}). Same wire format as
	// ProtocolOpenAIResponses but with Azure auth (api-key header),
	// deployment-name model mapping, and api-version query param.
	ProtocolAzureResponses Protocol = "azure-openai-responses"
	// ProtocolCodexResponses is the OpenAI Codex Responses API
	// (/codex/responses). Same wire format as ProtocolOpenAIResponses
	// but targets the ChatGPT backend, requires SSE streaming, rejects
	// sampling params, and carries Codex identity headers (originator,
	// version, chatgpt-account-id from JWT).
	ProtocolCodexResponses Protocol = "openai-codex-responses"
	// ProtocolCopilot is the GitHub Copilot multi-protocol adapter. It
	// routes each request to OpenAI Chat Completions, OpenAI Responses, or
	// Anthropic Messages based on the model, and requires a Copilot
	// token imported from the gh CLI / Copilot client.
	ProtocolCopilot Protocol = "github-copilot"
)

Jump to

Keyboard shortcuts

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