Providers
PiG speaks to inference providers through the provider registry shared with its Pi compatibility model. Each built-in provider has a Go implementation under ai/ that handles authentication, request shaping, and stream parsing. Extensions can register additional providers through the public extension API. See Extensions.
Built-in providers
Provider key | Wire | Auth method | Notes |
openai | Chat Completions or Responses, selected by model metadata | OPENAI_API_KEY | Provider-qualified models keep the openai key across both APIs. |
openai-codex | Codex Responses | OAuth via pig login openai-codex | Uses the built-in Codex OAuth provider. |
openrouter | OpenAI-compatible | OPENROUTER_API_KEY | Aggregator across many model providers. |
anthropic | Anthropic Messages | ANTHROPIC_AUTH_TOKEN, ANTHROPIC_OAUTH_TOKEN, ANTHROPIC_API_KEY, or subscription OAuth | Subscription tokens (sk-ant-oat) are sent with the Claude Code identity. Subscription auth shows a warning at session start. |
google | Google Generative Language API | GOOGLE_API_KEY | |
google-vertex | Vertex AI | Application Default Credentials | Requires gcloud auth application-default login. |
mistral | Mistral | MISTRAL_API_KEY | |
amazon-bedrock | Amazon Bedrock ConverseStream | AWS credentials chain | Uses standard AWS SDK resolution. |
azure-openai-responses | Azure-hosted OpenAI Responses | AZURE_OPENAI_API_KEY + endpoint | Endpoint comes from AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME; modern Foundry hosts ending in .ai.azure.com are supported. |
github-copilot | Copilot proxy | GitHub OAuth via pig login github-copilot | Token refresh is automatic; HTTP 401 means re-login. |
Authentication
PiG stores credentials in ~/.pig/agent/auth.json. The file is created on demand by pig login and is never read at module init. Environment variables (OPENAI_API_KEY, etc.) always take precedence over stored credentials at request time, matching upstream behavior - this lets per-shell or per-project keys override the global file.
OAuth providers
Built-in OAuth targets include anthropic, github-copilot, kimi-coding, openai-codex, openrouter, and xai. Each provider owns its flow. For example, GitHub Copilot uses device authorization, while callback-based providers can open a localhost callback server. Tokens are persisted to auth.json unless the provider owns another store, and supported providers refresh them when required.
A failed Copilot refresh reports an explicit reauthentication instruction:
github-copilot: refresh failed - run 'pig login' to re-authenticatepig login shapes
pig login # interactive picker
pig login <provider> # specific provider
pig logout <provider> # remove credentials for one providerCredential commands
pig auth resolves credentials the way a model request does and writes them for external clients. Each command needs --provider <provider>, --model <model>, or both.
pig auth check --provider openai --json # ready / not_ready / invalid, exit 0 / 1 / 2
pig auth print-api-key --provider openai # API key on stdout
pig auth print-bearer-token --provider openai-codex --min-expiry 1hCredential-printing commands write secrets to stdout. auth check prints a credential only with --credentials.
An OAuth login can wait for device authorization or a browser callback. This wait belongs to the provider flow. PiG does not start a model Session while pig login runs.
Environment variables (auth)
Variable | Effect |
OPENAI_API_KEY | Used by API-key-authenticated openai models. |
OPENROUTER_API_KEY | Used by openrouter. |
ANTHROPIC_AUTH_TOKEN | Used by anthropic as an Authorization: Bearer token when no stored credential or configured key exists. It takes precedence over ANTHROPIC_OAUTH_TOKEN and ANTHROPIC_API_KEY. |
ANTHROPIC_OAUTH_TOKEN | Used by anthropic as the API key. It takes precedence over ANTHROPIC_API_KEY. |
ANTHROPIC_API_KEY | Used by anthropic. |
GOOGLE_API_KEY | Used by google. |
MISTRAL_API_KEY | Used by mistral. |
AZURE_OPENAI_API_KEY | Used by azure-openai-responses. |
AZURE_OPENAI_BASE_URL | Azure OpenAI or Foundry endpoint. .openai.azure.com, .cognitiveservices.azure.com, and .ai.azure.com hosts are normalized to /openai/v1. |
AZURE_OPENAI_RESOURCE_NAME | Alternative to AZURE_OPENAI_BASE_URL; builds https://<resource>.openai.azure.com/openai/v1. |
AZURE_OPENAI_DEPLOYMENT_NAME_MAP | Optional comma-separated model=deployment map for Azure deployments. |
AWS_* | Standard AWS SDK chain for amazon-bedrock. |
PI_CACHE_RETENTION | Prompt cache retention passed to the provider. |
Provider resolution
When you select a model through --model, /model, Ctrl+P, or setModel(),
PiG parses provider/model. Always use provider-qualified model specs from
extensions and helpers; bare IDs default to openai and can route incorrectly.
For Copilot models the model ID itself may contain a slash (e.g. github-copilot/openai/gpt-5.5); pig's generatedModelSpec helper preserves trailing slashes when rebuilding specs from generated model objects.
Provider extensions
Extensions can add inference providers at register time. The host treats the config payload as opaque. The host owns lifecycle: providers registered by an extension are unregistered automatically on shutdown, reload failure, or quarantine fission. When a reload replaces an extension whose new register declares the same provider name, the registration is preserved across the swap so streaming completions are not interrupted.
Troubleshooting
Symptom | Likely cause | Fix |
Missing bearer or basic authentication | No API key in env, no token in auth.json | pig login <provider> or export the env var. |
Bad credentials (Copilot 401) | OAuth token expired or revoked | pig login github-copilot. |
| Model selector shows nothing | No providers have valid auth | Login or set an env var; check /login. |
| Cycling lands on the wrong model | Bare ID in a custom helper | Always pass provider/model; see Models. |