Pi

Pi connects to any OpenAI-compatible endpoint through models.json in its agent directory. A dummy key makes the models available; Foglare ignores it.

Prerequisites

  • Pi installed (pi on your PATH).
  • A Foglare API key (sk-fog-…) from the dashboard. Export it as FOGLARE_API_KEY; inference requires a real key. Pi hides models without a credential.
  • Model ids from GET /v1/models. The config lists the tiers; add direct ids the same way.

Configuration

Create or merge into ~/.pi/agent/models.json. The baseUrl includes /v1; Pi appends /chat/completions for the openai-completions API. Opening /model reloads the file, no restart needed.

~/.pi/agent/models.json

{
  "$schema": "https://pi.dev/schemas/models.schema.json",
  "providers": {
    "foglare": {
      "baseUrl": "https://api.foglare.com/v1",
      "api": "openai-completions",
      "apiKey": "$FOGLARE_API_KEY",
      "models": [
        { "id": "auto:fast", "name": "Foglare Fast", "reasoning": false, "input": ["text"], "contextWindow": 128000, "maxTokens": 16384, "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 } },
        { "id": "auto:M", "name": "Foglare Medium", "reasoning": false, "input": ["text"], "contextWindow": 128000, "maxTokens": 16384, "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 } },
        { "id": "auto:L", "name": "Foglare Large", "reasoning": true, "input": ["text"], "contextWindow": 128000, "maxTokens": 32768, "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 } },
        { "id": "auto:XL", "name": "Foglare XL", "reasoning": true, "input": ["text"], "contextWindow": 128000, "maxTokens": 32768, "cost": { "input": 0, "output": 0, "cacheRead": 0, "cacheWrite": 0 } }
      ]
    }
  }
}
Field Value Why
baseUrlhttps://api.foglare.com/v1Versioned root, no endpoint path.
apiopenai-completionsWire protocol. Foglare also speaks anthropic-messages at the root without /v1 if you prefer that shape.
apiKey$FOGLARE_API_KEYReads the env var: your sk-fog key from the dashboard. Required for inference. A literal value works too.
models[].idcatalog idSent verbatim as the model field.
contextWindow / maxTokenslocal budgetPi's own context accounting. Conservative placeholders; adjust to the model you pin.

Launch on a Foglare model directly, or pick it with /model inside a session (Ctrl+S saves it as the default):

Shell

pi --provider foglare --model auto:fast

Config format verified against the Pi models documentation. The context-window and token figures are sample values, not per-model limits; set them from the model you actually use.

Verify

Check the endpoint from your shell first: chunk lines ending in data: [DONE]. Then start Pi and send a message.

curl the chat endpoint

curl -N https://api.foglare.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-fog-YOUR_KEY" \
  -d '{"model":"auto:fast","stream":true,"messages":[{"role":"user","content":"Hello"}]}'

Expected stream (trimmed)

data: {"id":"fglr_...","object":"chat.completion.chunk","created":1795312786,"model":"auto:fast","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}

data: {"id":"fglr_...","object":"chat.completion.chunk","created":1795312786,"model":"auto:fast","choices":[{"index":0,"delta":{"content":"! How can I help?"},"finish_reason":null}]}

data: {"id":"fglr_...","object":"chat.completion.chunk","created":1795312786,"model":"auto:fast","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop"}]}

data: [DONE]

List accepted model ids (trimmed response)

curl https://api.foglare.com/v1/models

{
  "object": "list",
  "data": [
    { "id": "deepseek-v4.1-flash", "object": "model", "created": 1763769600, "owned_by": "foglare" },
    { "id": "qwen4-max", "object": "model", "created": 1763769600, "owned_by": "foglare" },
    { "id": "auto:fast", "object": "model", "created": 1763769600, "owned_by": "foglare" }
  ]
}

Troubleshooting

Symptom Fix
404, model not found The model id is not in the catalog. List accepted ids with GET /v1/models. Tier ids are auto:fast, auto:S, auto:M, auto:L, auto:XL; direct ids carry no suffix.
404 on the endpoint path The base URL is wrong for this tool. Check whether it expects the root (https://api.foglare.com) or the versioned root (https://api.foglare.com/v1); the configuration table above says which.
503, capacity exhausted All upstream routes are busy or rate-limited. The error message says when to retry. Retry after that window, or switch to a routing tier so the gateway picks healthy capacity.
Output arrives all at once, or the stream hangs Something between you and the gateway is buffering SSE. Use curl -N, disable proxy buffering (nginx: proxy_buffering off), and read the response as a stream instead of waiting for the full body.
Foglare models missing from /model Pi only shows models whose provider has a usable credential. Export FOGLARE_API_KEY with your sk-fog key from the dashboard so $FOGLARE_API_KEY resolves, and check the file is at ~/.pi/agent/models.json (or PI_CODING_AGENT_DIR if you moved it).
Changes to models.json not applied Open /model once; that reloads the file. A JSON syntax error makes Pi skip the file silently, so validate it.
Endpoint rejects requests Check api is openai-completions and baseUrl ends in /v1 without /chat/completions appended.