PiG Documentation

Guides and references for configuring, using, and extending PiG.

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
openaiChat Completions or Responses, selected by model metadataOPENAI_API_KEYProvider-qualified models keep the openai key across both APIs.
openai-codexCodex ResponsesOAuth via pig login openai-codexUses the built-in Codex OAuth provider.
openrouterOpenAI-compatibleOPENROUTER_API_KEYAggregator across many model providers.
anthropicAnthropic MessagesANTHROPIC_AUTH_TOKEN, ANTHROPIC_OAUTH_TOKEN, ANTHROPIC_API_KEY, or subscription OAuthSubscription tokens (sk-ant-oat) are sent with the Claude Code identity. Subscription auth shows a warning at session start.
googleGoogle Generative Language APIGOOGLE_API_KEY
google-vertexVertex AIApplication Default CredentialsRequires gcloud auth application-default login.
mistralMistralMISTRAL_API_KEY
amazon-bedrockAmazon Bedrock ConverseStreamAWS credentials chainUses standard AWS SDK resolution.
azure-openai-responsesAzure-hosted OpenAI ResponsesAZURE_OPENAI_API_KEY + endpointEndpoint comes from AZURE_OPENAI_BASE_URL or AZURE_OPENAI_RESOURCE_NAME; modern Foundry hosts ending in .ai.azure.com are supported.
github-copilotCopilot proxyGitHub OAuth via pig login github-copilotToken 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-authenticate

pig login shapes

pig login                 # interactive picker
pig login <provider>      # specific provider
pig logout <provider>     # remove credentials for one provider

Credential 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 1h

Credential-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_KEYUsed by API-key-authenticated openai models.
OPENROUTER_API_KEYUsed by openrouter.
ANTHROPIC_AUTH_TOKENUsed 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_TOKENUsed by anthropic as the API key. It takes precedence over ANTHROPIC_API_KEY.
ANTHROPIC_API_KEYUsed by anthropic.
GOOGLE_API_KEYUsed by google.
MISTRAL_API_KEYUsed by mistral.
AZURE_OPENAI_API_KEYUsed by azure-openai-responses.
AZURE_OPENAI_BASE_URLAzure OpenAI or Foundry endpoint. .openai.azure.com, .cognitiveservices.azure.com, and .ai.azure.com hosts are normalized to /openai/v1.
AZURE_OPENAI_RESOURCE_NAMEAlternative to AZURE_OPENAI_BASE_URL; builds https://<resource>.openai.azure.com/openai/v1.
AZURE_OPENAI_DEPLOYMENT_NAME_MAPOptional comma-separated model=deployment map for Azure deployments.
AWS_*Standard AWS SDK chain for amazon-bedrock.
PI_CACHE_RETENTIONPrompt 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 authenticationNo API key in env, no token in auth.jsonpig login <provider> or export the env var.
Bad credentials (Copilot 401)OAuth token expired or revokedpig login github-copilot.
Model selector shows nothingNo providers have valid authLogin or set an env var; check /login.
Cycling lands on the wrong modelBare ID in a custom helperAlways pass provider/model; see Models.
Adapted from upstream Pi documentation · Upstream documentation ↗ · MIT License