Skip to main content

pi-sidecar

A standalone HTTP service that wraps the Pi coding agent SDK (requires @earendil-works/pi-coding-agent ≥ 0.99.0), exposing AI sessions over a simple JSON API. Ships with a Python client for easy integration.

📖 Full Documentation

Features

  • Session management — create, prompt, abort, and delete AI sessions over REST; optionally supply a provider-agnostic, session-scoped API key
  • Model discovery — discover models from ACPX, CLI, and built-in providers. See key-scoped model discovery for user keys.
  • Provider discovery — GET /providers lists every provider registered in the initialized runtime, including built-ins and extensions, even without discoverable models or ambient credentials. The JSON response is { "providers": [{ "provider": string, "supportsSessionApiKey": boolean }] }. provider is the exact ID; supportsSessionApiKey says whether POST /sessions accepts api_key, not whether the server has credentials. No credentials or auth diagnostics are returned. Python: await SidecarClient.get_providers() returns a typed list of these records. Use discovery to enumerate providers, GET /models for available models, and GET /models/:provider/status for details about a known provider.
  • Provider diagnostics — GET /models/:provider/status reports registration, model count, auth status, and supportsSessionApiKey (a boolean indicating whether POST /sessions accepts api_key for that provider, regardless of server credentials; false for unknown, headless-excluded, and ambient CLI/ACPX providers). Python: SidecarClient.get_model_provider_status(). Full auth detail on loopback; on non-loopback binds (SIDECAR_HOST / DEV_MODE) authStatus/authCheck are redacted to { configured } / { type }; supportsSessionApiKey remains public on both binds and in 404 responses
  • Custom tools — plug in domain-specific tools at session creation via custom_tools
  • HTTP-backed tools — custom tools with http config get automatic request execution with parameter interpolation and security hardening
  • Subagent delegation — delegate tasks to specialized agents via the subagent tool (loaded as a Pi SDK extension)
  • Watchdog — opt-in health-check poller for companion backend liveness
  • Localhost-only — binds to 127.0.0.1 by default; no auth needed behind the network boundary

Packages

Package Language Install
@myk-org/pi-sidecar TypeScript npm install @myk-org/pi-sidecar
pi-sidecar-client Python ≥ 3.10 uv pip install pi-sidecar-client

The npm tarball is the Node server only. Python wheels/sdists publish to PyPI — they must not ship inside @myk-org/pi-sidecar even though uv build writes them to the same dist/ as tsc.

Quick Start

from pi_sidecar_client import call_ai_once

result = await call_ai_once(
    "Summarize this log file",
    ai_provider="gemini",
    ai_model="gemini-2.5-flash",
    system_prompt="You are a log analyst.",
)
print(result.text)

To override the server's stored/environment API key for one session, pass api_key=user_api_key to SidecarClient.create_session, call_ai, or call_ai_once. The wire field is api_key in POST /sessions (a non-empty string of at most 1,024 characters); the response remains { "session_id": "..." }. The key applies only to the selected provider and that session, takes precedence over server credentials, and is held in memory until the session is deleted or expires. Omitting it preserves server credential fallback. Providers without Pi API-key auth capability reject it with HTTP 400; OAuth, Vertex/ADC and CLI login state are not configured by this field. Keys are not saved in session files, returned in API responses, or passed to nested agents. Treat sidecar access as privileged: its default loopback bind is not an authentication boundary against local users.

# Start the sidecar
npm run build && node dist/server.js  # listens on 127.0.0.1:9100

# Or, for local development (background by default; default port 9201 — override with SIDECAR_PORT; see --help):
scripts/start-sidecar.sh

See the Consumer Integration Guide for Docker, Python client, and deployment best practices. See the full documentation for everything else.

Key-scoped model discovery

GET /models uses the server's credentials. Static getModels metadata cannot verify what a supplied key can access. For providers with supportsSessionApiKey: true in GET /providers, query with the key instead:

curl -s -X POST http://127.0.0.1:9100/models/for-api-key \
  -H 'Content-Type: application/json' \
  -d '{"provider":"openai","api_key":"<your-key>"}'
# Returns: {"models": [...], "modelListingSupported": true}

The response is { "models": [...], "modelListingSupported": boolean }. A provider with native key-scoped listing returns modelListingSupported: true; models: [] then means the listing returned no models. A provider without native key-scoped listing returns { "models": [], "modelListingSupported": false }. In that case, ask the user to enter a model ID. A canonical builtin always supports key-scoped listing on its own host, even when its catalog mixes APIs (OpenRouter fronts Anthropic models alongside OpenAI ones); a models.json baseUrl override or a custom gateway is still refused, so a request-supplied endpoint never receives the credential. A listing is only key-listed: it does not verify that a prompt will work. Google results require generateContent; known non-generation OpenAI model families are excluded, but remaining IDs are not prompt-verified. Do not use static catalog entries as verified models for that key. Known static IDs can be used with a supplied key. Unknown IDs can create a session only when the native listing supplies reliable positive input and output token limits (currently Google); otherwise POST /sessions returns HTTP 400 for missing model metadata.

In Python, await SidecarClient.get_models_for_api_key(provider, api_key) returns the full dictionary, including models and modelListingSupported. Providers without supportsSessionApiKey return HTTP 400. The lookup is request-local: the sidecar does not cache the supplied key or result.

Custom providers and settings (agent dir)

By default the sidecar's internal runtime keeps its catalog in the ephemeral, non-configurable scratch dir /tmp/pi-sidecar-agent. Deployments that need to register custom pi providers or supply pi settings point the sidecar at a persistent agent dir instead:

# Environment variable (honored by npx pi-sidecar / pi-sidecar-start / node dist/server.js)
export PI_SIDECAR_AGENT_DIR=/etc/pi-sidecar/agent
npx pi-sidecar
// Or programmatically
import { startSidecar } from "@myk-org/pi-sidecar";
startSidecar({ agentDir: "/etc/pi-sidecar/agent" });

Precedence: explicit agentDir option → PI_SIDECAR_AGENT_DIR (trimmed, non-empty) → /tmp/pi-sidecar-agent. Resolution is logged at startup. Use an absolute path — a relative path resolves against the sidecar process's cwd, which differs between the CLI entry and embedded startSidecar() callers.

Files honored from the configured dir (read once at process start — restart the sidecar after changing them):

File Effect
models.json Custom pi providers registered on the shared runtime — listed by GET /models and GET /providers, usable in POST /sessions
auth.json Provider credentials for the shared runtime (same format as interactive pi's auth.json)
settings.json Seeded into the in-memory settings store for the internal runtime and every session (e.g. defaultProvider)

A models.json apiKey may reference an environment variable (e.g. "$ENMAAS_API_KEY") — the variable must exist in the sidecar process's environment (pass it through in Docker with -e / Env:). Worked example — an EnMaaS OpenAI-compatible gateway at /etc/pi-sidecar/agent/models.json:

{
  "providers": {
    "enmaas": {
      "baseUrl": "https://enmaas.example.com/v1",
      "api": "openai-completions",
      "apiKey": "$ENMAAS_API_KEY",
      "models": [
        { "id": "enmaas/gpt-4o", "name": "GPT-4o via EnMaaS" }
      ]
    }
  }
}
export PI_SIDECAR_AGENT_DIR=/etc/pi-sidecar/agent
export ENMAAS_API_KEY=<your-key>
npx pi-sidecar
# GET /models now lists enmaas/gpt-4o (provider "enmaas");
# POST /sessions accepts {"provider": "enmaas", "model": "enmaas/gpt-4o", ...}

Notes:

  • The per-request agent_dir field on POST /sessions still overrides only the session's resource loading (skills/prompts/agents) — it never reconfigures the shared runtime.
  • There is no REST API change: /health, /models, /providers, and /sessions keep their semantics; the configured dir only changes what the runtime is seeded with at startup.
  • Settings seeded from settings.json never re-enable compaction — sidecar sessions are short-lived and always run with compaction disabled.

CLI Commands

After installing @myk-org/pi-sidecar, two CLI commands are available:

# Start the sidecar server (Node.js entry point)
npx pi-sidecar

# Start/stop via shell script (background mode, dev defaults on port 9201)
npx pi-sidecar-start
npx pi-sidecar-start --stop
npx pi-sidecar-start --help

License

Apache-2.0

Metadata

Release files for pi-sidecar-client 4.8.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pi-sidecar-client 4.8.5
File Size Uploaded
pi_sidecar_client-4.8.5.tar.gz 22.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pi-sidecar-client 4.8.5
File Interpreter ABI Platform
pi_sidecar_client-4.8.5-py3-none-any.whl Python 3 none any Details

Total release size: 41.0 kB

Release files / pi_sidecar_client-4.8.5.tar.gz

Download URL pi_sidecar_client-4.8.5.tar.gz
Size 22.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f1100bbd8918ab2a485d7b924aa067a63dfc7fcbacc565c54577351a5757e94a
BLAKE2b-256 checksum
How to use checksums
cd79c8b66628cd6e182960b523f1ce8169a89ceb707400932275c5f4a76202ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / pi_sidecar_client-4.8.5-py3-none-any.whl

Download URL pi_sidecar_client-4.8.5-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
032ec2bbd5db8a7aa461550a1b3f5021c1ed398de80af43dfeb3d71e395cc448
BLAKE2b-256 checksum
How to use checksums
430c3949a0c1b67a4641b74142e45154ac6bf781ec273ab508d400fc50903595
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

4.10.0

2 release files

4.9.0

2 release files

This release

4.8.5 This release

2 release files

4.8.4

2 release files

4.8.3

2 release files

4.8.2

2 release files

4.8.1

2 release files

4.8.0

2 release files

4.7.3

2 release files

4.7.2

2 release files

4.7.1

2 release files

4.7.0

2 release files

4.6.5

2 release files

4.6.4

2 release files

4.6.3

2 release files

4.6.2

2 release files

4.6.1

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.1

2 release files

4.4.0

2 release files

4.3.12

2 release files

4.3.11

2 release files

4.3.10

2 release files

4.3.9

2 release files

4.3.8

2 release files

4.3.7

2 release files

4.3.6

2 release files

4.3.5

2 release files

4.3.4

2 release files

4.3.3

2 release files

4.3.2

2 release files

4.3.1

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.5

2 release files

4.1.3

2 release files

4.1.2

2 release files

4.1.1

2 release files

1.5.0

1 release file

1.4.0

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page