Skip to content
Edit this page View source of this page

Providers & Models

Pegg talks directly to LLM APIs using your own credentials. A provider is a named, preconfigured endpoint; a driver is the wire protocol it speaks.

Providers

237 providers are registered out of the box. Every provider exposes a model list that Pegg fetches at startup and caches locally. See the Provider catalog for the full list of built-in providers, their drivers, and default base URLs.

Pegg Forever

pegg-forever is the first-party Pegg provider. Its default base URL is https://forever.pegg.dev/v1, and it speaks the OpenAI wire protocol. You can add it in two ways:

  • Browser login — run pegg login-pegg, or choose Login to Pegg in the TUI or desktop first-run screen. Pegg opens the website, asks you to approve a device, creates a revocable API key assigned to your user, and stores the provider in ~/.pegg/pegg.json.
  • API key — paste an existing Pegg API key with pegg login-pegg --token, or use Use API key in the first-run screen.

The provider is also available under Settings → General → Provider → pegg-forever after setup, where both login methods are offered. A failed /models check does not block saving; Pegg keeps the provider and retries model discovery later.

Team providers

pegg team adds a provider named pegg-team <team>. It behaves like an OpenAI-compatible provider, but its base URL points at the team BYOK gateway and its models and defaults come from the team's website configuration. Manage the upstream keys on Team AI in the website, not with pegg login.

See Team AI.

Speech-to-text providers

Speech-to-text has its own provider list under stt, separate from chat providers. Five providers are registered out of the box:

Provider Driver Default base URL
assemblyai assemblyai https://api.assemblyai.com
fireworks openai https://api.fireworks.ai/inference/v1
groq openai https://api.groq.com/openai/v1
openai openai https://api.openai.com/v1
together openai https://api.together.xyz/v1

Each provider has a built-in model catalogue. Choose a pair with stt.provider and stt.model; models marked stream also support realtime streaming.

Provider Built-in models
assemblyai best, nano, universal-3-6-pro (stream), universal-3-5-pro (stream), universal-streaming-english (stream), universal-streaming-multilingual (stream)
fireworks whisper-v3
groq whisper-large-v3, whisper-large-v3-turbo, distil-whisper-large-v3-en
openai whisper-1, gpt-4o-transcribe, gpt-4o-mini-transcribe
together openai/whisper-large-v3

Custom OpenAI-compatible endpoints are declared under stt.providers with a driver and base_url. A models array supplies their catalogue; when it is present it replaces the built-in list for that provider. This is how pegg team wires the team gateway as pegg-team <team> (driver openai).

See Declaring STT models and the stt config reference.

Authentication

Driver Auth mechanism
openai Authorization: Bearer <api_key>
claude x-api-key: <api_key> plus anthropic-version: 2023-06-01
gemini ?key=<api_key> query parameter

Requests also send HTTP-Referer: https://github.com/peggco/pegg and X-Title: pegg unless you override the headers in config.

Subscriptions

Some providers use an existing subscription instead of an API key, reusing the OAuth credentials that the official CLI already stored after you signed in with it. For these subscription providers, Pegg never performs the OAuth login itself and never writes to those files except to refresh an expiring token. Pegg Forever is different: pegg login-pegg performs its own browser approval flow and stores a regular API key for the pegg-forever provider.

Provider Signs in with Credentials
claude claude (Claude Code) ~/.claude/.credentials.json (or $CLAUDE_CONFIG_DIR); on macOS the Claude Code-credentials login keychain item
codex codex ~/.codex/auth.json (or $CODEX_HOME)
cline cline auth ~/.cline/data/settings/providers.json (or $CLINE_DATA_DIR)
cline-pass cline auth (ClinePass) ~/.cline/data/settings/providers.json

On macOS, Claude Code keeps its credentials in the login keychain rather than in .credentials.json. Pegg reads the file first and falls back to the Claude Code-credentials keychain item (through /usr/bin/security) when the file is missing or holds no OAuth block. A token refreshed from the keychain is written back to the keychain, never to disk, so macOS needs no extra setup. The keychain may ask you to allow access the first time. Setting CLAUDE_CONFIG_DIR pins Pegg to that directory's .credentials.json and turns the keychain fallback off.

Cline exposes two separate providers: cline is pay-as-you-go (billed against your account balance) and cline-pass uses your ClinePass subscription. The ClinePass models are prefixed cline-pass/ and are listed by the cline-pass provider.

# sign in with the official CLI first
claude        # or: codex   /   cline auth

# then enable the provider in pegg
pegg login --provider claude

# remove it from pegg (the official CLI credentials are left untouched)
pegg logout --provider claude

In the TUI, open Settings → General → Provider, pick a subscription provider, and follow the prompt. If you are not signed in, pegg shows the exact command to run and lets you retry. Tokens are refreshed automatically before they expire and the rotated tokens are written back to the official CLI's file.

Adding a provider

Interactive

pegg login

Pick a provider from the list and paste the API key (input is masked). The key may be left empty for endpoints that do not need one.

Non-interactive

pegg login --provider groq --api-key gsk_...

The provider is synced first — Pegg fetches its model list and only saves the provider if that succeeds (35 second timeout). This guarantees a freshly added provider has usable models immediately.

CLI with full options

pegg providers add exposes every config field (driver, base_url, headers, timeout, max_retries):

pegg providers add --name groq --api-key gsk_...
pegg providers add --driver openai --base-url http://localhost:11434/v1 --api-key ollama --timeout 120

Registered names use built-in endpoints; base_url/driver are ignored for them. For custom endpoints, use a bare driver entry or combine a custom name with a driver:

pegg providers add --driver openai --base-url http://localhost:11434/v1 --api-key ollama --timeout 120
pegg providers add --name my-gw --driver openai --base-url http://localhost:11434/v1 --api-key ollama

providers add runs without prompts when any of --name, --driver, or --base-url is given; headers default to empty and the API key may be left empty. With no flags it starts the interactive picker. Picking its "Custom endpoint" option prompts for a provider name and a driver, so the saved entry is a named custom endpoint (the name must not collide with a registered provider). Models are fetched in the background after saving — a failed fetch does not block the add, run pegg providers refresh to retry.

TUI

Open Settings with Ctrl+P → General → Provider. The list includes both built-in providers and any configured provider whose name is not registered, such as custom endpoints and pegg-team <team>. Existing providers show Use existing configuration / Configure again; new ones prompt for an API key.

Config file

Keys are stored in plaintext in ~/.peggco/pegg.json:

{
  "providers": [
    { "provider": "openai", "api_key": "sk-..." },
    { "provider": "groq", "api_key": "gsk_...", "timeout": 60 }
  ]
}

Keys are masked in pegg providers list and pegg config show.

Providers that only allow the first system message

Some providers reject a system message that is not the first message of the conversation ("System message must be at the beginning"). Pegg normally sends reminders and compaction summaries as system messages, so those providers fail mid-run.

Set system_first_only on the provider entry to fold every late system message into the neighbouring user or tool message instead:

{
  "providers": [
    { "provider": "zhipu", "api_key": "...", "system_first_only": true }
  ]
}

The option is off by default and is only read from ~/.pegg/pegg.json — there is no CLI flag or TUI switch for it. Re-adding a provider with pegg providers add keeps the setting.

The website can set the same option:

  • Pegg Connect → Settings → Providers → the provider dialog → System prompt first only. The value is stored in the local pegg.json.
  • Team AI → the team provider dialog → System prompt first only. The value is stored on the website and handed to the CLI when the team is connected, so every team member gets the same behaviour.

The folded content keeps its <system-reminder> markup, so the agent still reads it as a reminder. The conversation history itself is not modified; only the request that is sent to the provider is rewritten.

Custom and OpenAI-compatible endpoints

To use a gateway, proxy, or local runtime, configure a raw driver instead of a named provider. base_url is required for drivers:

{
  "providers": [
    {
      "driver": "openai",
      "base_url": "http://localhost:11434/v1",
      "api_key": "ollama",
      "timeout": 120,
      "headers": { "X-Custom": "value" }
    }
  ]
}

The same works for "driver": "claude" and "driver": "gemini" endpoints that implement those wire protocols.

The same entry can be added from the CLI:

pegg providers add --driver openai --base-url http://localhost:11434/v1 --api-key ollama

Managing providers

pegg providers add --name anthropic --api-key your-api-key # add or replace a provider
pegg providers list                    # name, masked key, cached model count
pegg providers refresh                 # re-fetch models for every provider
pegg providers refresh --provider xai  # re-fetch one provider
pegg providers remove groq             # remove provider and its cached models
pegg models                            # list cached models
pegg models --provider deepseek        # filter by provider

Model lists are cached in ~/.pegg/cache.db (or cache.json with the JSON cache driver). pegg cache clear empties the cache; pegg providers refresh bypasses it and fetches from the network.

Decision models

Alongside chat models, Pegg can use decision models — models that answer typed questions (yes/no, choice, or an ordered score) about a piece of state instead of generating text. The supported decision model is JEV (typesafe/jev-1.14) from TypeSafe, served by both Pegg Forever (https://forever.pegg.dev/v1/chat/decisions) and OpenRouter (https://openrouter.ai/api/alpha/decisions).

Decision models reuse the regular provider configuration: the pegg-forever or openrouter provider entry and its API key are shared, so one login covers both chat and decisions. There is no separate model list to fetch — the model ID is passed per request.

Pegg uses decision models for the permission judge, the smart router, and memory relevance gating. When a decision-capable provider has an API key, the judge uses JEV by default (even without judge_provider set), and falls back to the judge LLM on any error. Configure the behavior with judge_provider, judge_model, and judge_threshold — see Permissions and Config.

{
  "providers": [{ "provider": "pegg-forever", "api_key": "vsk_live_..." }],
  "permission": {
    "judge_provider": "pegg-forever",
    "judge_model": "typesafe/jev-1.14",
    "judge_threshold": 0.8
  }
}

Smart router

The smart router is a system model that picks the best model for each agent and task at run time, instead of using one model for everything. It is backed by a decision model — JEV by default, or your preferred LLM if no decision provider has an API key — and falls back to the preferred model when nothing is available.

Enable it in config (smart_router.enabled), then pick Smart Router in the TUI at Settings → General → Model (listed above the regular models) or pass --model smart-router on the CLI. When enabled, subagents (explorer, developer, ...) are also routed automatically.

Per-agent preferences under smart_router.agents support three layers: default model lists, per-difficulty lists (trivial/moderate/complex — the decision model scores the task first and routes to the matching bucket), and images lists for vision-capable variants. Models without image support are excluded automatically when the run has image attachments. The decision model's pick is always used — there is no confidence threshold. See Config.

Model selection

When a run starts, Pegg resolves a provider/model in this order:

  1. Explicit — --provider and --model must match a known model (by ID or display name), otherwise the run fails.
  2. Model only — the model is searched across all providers. A single match is used automatically; multiple matches open a picker.
  3. Provider only — a picker lists that provider's models.
  4. Preferred — the provider/model of the most recent non-subagent session in the current project directory, falling back to the first model of the first provider. Resolution has a 30 second timeout.
pegg run --provider openai --model gpt-4o "Explain this error"
pegg run --model deepseek-chat "Refactor this function"
pegg run --select-model "Do something"

The same resolution logic backs the HTTP /api/run endpoint and the ACP server.

Model metadata

Model lists are enriched with metadata fetched and cached under the models_cache key. For each model this includes:

Field Used for
max_input_tokens, max_tokens Context-window usage indicator
max_output_tokens The request's output token budget (max_tokens / max_output_tokens)
input_cost_per_token, output_cost_per_token, cache_read_cost_per_token Cost display in the TUI status bar and session usage
supports_reasoning, reasoning_options The TUI Reasoning setting (default, low, medium, high)
reasoning_options[].type, .values The effort levels offered for the model (effort values, max_tokens bounds)
modalities.input Whether image/audio/video attachments are allowed
tool_call, structured_output, temperature Capability checks

Lookup tries provider/model first, then the bare model ID, then a substring fallback. Unknown models still work; they simply have no metadata.

Metadata can also be declared directly in pegg.json — see Declaring models. A declared model wins over the discovered one, and a provider without a reachable /models endpoint still works with the declared catalogue.

Output token budget

The request's output budget comes from the model's max_output_tokens. When the model is unknown the field is omitted and the provider default applies. Built-in agents do not pin their own value, because reasoning tokens are counted against that budget: a small cap makes a thinking model spend everything on internal reasoning and return an empty answer.

When the provider reports finish_reason=length anyway, Pegg keeps the partial answer and asks the model to continue (up to three times). If the model produced no content at all, the budget is doubled up to the model limit and retried. Once the limit is reached the run fails with agent: response truncated by the output token limit instead of reporting an empty response. The TUI prints a warning when a run ends truncated, and ACP clients receive stopReason: max_tokens.

On the website, Team AI model entries carry the same metadata. The model dialog has fields for the context window, the output limit, the prices, the input and output types and the capability flags; a model sync only fills the keys that are still missing, so manual values survive.

Reasoning effort

Models that support reasoning expose effort levels. Set it per run in the TUI (Settings → General → Reasoning) or via the SDK's ReasoningEffort field. The value is persisted with the session and shown in the status bar.

Attachments

Image, audio, and video attachments are validated against the model's input modalities before sending. Media the model does not support is never sent inline (the agent still gets the file by path). Non-media files — PDFs, text, CSV, and so on — are always referenced by path rather than uploaded. See Adding Context.

Failures and retries

The built-in retry middleware wraps every LLM call in all agents:

  • Temporary provider errors (HTTP 429 and 5xx) are retried with a backoff of 1s, 3s, 10s, 30s, 1m, 5m, then every 5 minutes.
  • Other errors are retried too, unless the run was cancelled.
  • Streaming calls are only retried before any content, reasoning, or tool call has been emitted.
  • While waiting, the CLI and TUI show a transient Request failed (attempt N): ... retrying in Xs message.

There is currently no automatic failover to a secondary provider — configure retries and switch models manually if a provider is down.

Troubleshooting

pegg doctor                            # connectivity + model count per provider
pegg logs --level ERROR                # recent errors
pegg providers refresh --provider X    # force a fresh model fetch

See Troubleshooting for details.