Invincible — AI Continuity Gateway & Local MCP Agent
The Python package is named
invincible(the repository directory isai-gateway). Throughout this repo the project is referred to as Invincible.
Project direction: Invincible is a remote-first, multi-user AI continuity platform — accounts, projects, shared memory across models, context intelligence, and a web dashboard (invincible-ai.me). Users install one CLI command on their own PC and pair with the hosted service; the database, provider credentials, and all state live server-side. The same code runs as a single-user self-host. See docs/ROADMAP.md for the direction, what is implemented today, and what is planned.
What is Invincible?
A remote-first, multi-user AI gateway: one Python (FastAPI) service that many users sign into, each with their own projects, API keys, provider credentials, memory, and continuity — served over HTTPS from any host. The same code runs as a single-user self-host on a laptop (the local/self-hosted mode is supported indefinitely); nothing else changes between the two.
It serves three roles in one process:
- Self-Service BYOK Gateway — an OpenAI-compatible
/v1/chat/completionsendpoint where every user authenticates with their owninv_API key and routes through their own connected provider credentials (BYOK), with transparent failover on rate limits (429) and server errors, so a free-tier 429 no longer kills an agent's workflow. It also speaks the Anthropic Messages API (POST /v1/messages) and the OpenAI Responses API (POST /v1/responses), so Claude Code, Codex CLI, and other native clients plug in with a one-line config change. - Multi-user account platform — browser accounts (email + password, or GitHub), a dashboard for sessions, memory, usage, and provider credentials, and strict per-user ownership: one account can never read another's sessions, memory, or history.
- MCP Tool Server — a JSON-RPC 2.0
/mcpendpoint exposingread_file,execute_bash, andwrite_fileto a cloud-hosted AI. WithINVINCIBLE_AGENT_ROUTING=1(required on any public multi-user deployment) the tools execute on the user's own paired machine, so a remote AI acts on their files under their account.
Why it exists
- The 429 problem. AI coding agents using free/open-source providers get killed when they hit a rate limit. Invincible sits between the agent and the providers; on a 429 (or 5xx) it records the failure, puts the provider in a short cooldown, and retries the next credential in the user's own routing order. The agent sees a single, stable endpoint.
- The cloud-to-local gap. Cloud AI tools (e.g. the Claude web/mobile app) can reason well but cannot read the user's files, write to disk, or run terminal commands. Invincible's MCP server exposes those capabilities over HTTPS, so a remote model can act on each user's own machine — under that user's confirmation for anything destructive.
Features
| Feature | What it gives you |
|---|---|
| Remote-first, multi-user | One deployment serves many accounts over HTTPS: browser accounts (email+password or GitHub), per-user projects/API keys/provider credentials, a dashboard, and stri[...] |
| BYOK routing | Every user connects their own provider credentials (dashboard → Providers) and routes only through them: auto/pinned/chain routing per user, 429/5xx → cooldown + nex[...] |
| Exponential cooldown | 30s → 60s → 120s → 240s → capped at 300s; a success resets the counter (in-memory, process-scoped). |
| Conversation memory | PostgreSQL-backed, keyed by the X-Session-Id header (default default). History is merged into every request and the assistant reply is persisted back. |
| Context trimming | Per-credential max_context; system messages always kept; everything else dropped as atomic turns (an assistant tool_calls is never separated from its tool results); [...] |
| Per-provider timeouts | Split connect/read/write/pool with sane defaults and per-provider overrides. |
| MCP tool server | read_file (no approval), execute_bash and write_file (staged, then approved via a token round-trip through the confirm_action tool), guarded by denylists and an **O[...] |
| Accounts & projects (Phase 3) | Sign up / sign in in a browser (email + argon2id passwords, or GitHub login), manage your own projects and inv_ API keys over HTTP, list your sessions �[...] |
| Protocol-agnostic | Native OpenAI, Anthropic, and Responses protocols, all translated into one internal message model. Claude Code works with ANTHROPIC_BASE_URL pointing at the[...] |
Installation
Users: one install command. That's all.
pip install -U invincible-ai # safe to re-run: installs, or upgrades in place
invincible connect # first run: browser opens → sign in or register → Approve
Prefer an isolated CLI that never touches your project's Python environment?
pipx install invincible-ai (or uv tool install invincible-ai); upgrade it
with pipx upgrade invincible-ai / uv tool upgrade invincible-ai.
Already on an older release? Re-run the same command (
pip install -U invincible-ai).No such command 'connect'means you are on 0.5.x: upgrade, or use the old spellinginvincible harness connect. Self-hosters runinvincible db upgradeafter every upgrade.
The first run pairs your machine with the hosted service
(https://invincible-ai.me — the default): your browser opens, you
register or sign in, click Approve, and the agent starts. There is
no database to set up, no .env, no provider configuration on your
machine — your account, connected provider keys, memory, and sessions all
live on the hosted service. The local agent only executes confirmed tool
actions on your PC. Finish by adding https://invincible-ai.me/mcp as the
MCP connector in Claude (or any MCP client) — see
Quick Start. (invincible login does the same pairing
without starting the agent loop.)
Operators only: running your own server. Everything above works
against the hosted service without it. If you self-host or operate an
instance, you need Python 3.10+ and a PostgreSQL database (all state —
conversations, OAuth grants, task state, staged approvals — lives there;
INVINCIBLE_DB_URL is required to start):
pip install -e .
invincible setup --db-url postgresql://user:pass@your-db-host:5432/invincible
invincible db upgrade # create/migrate the schema (explicit, never auto-run)
invincible start --host 0.0.0.0 # omit --host for a loopback-only dev server
TLS, $PORT, proxy headers, the two-role database split, the container
start command, required secrets, and the go-live checklist:
docs/DEPLOYMENT.md. Development shortcuts
(invincible dev-db, docker compose up) and the full CLI reference:
docs/CONFIGURATION.md.
Upgrading
One upgrade command per install channel:
| Install | Upgrade | Verify |
|---|---|---|
| pip (user site or venv) | pip install -U invincible-ai |
invincible --version |
| pipx | pipx upgrade invincible-ai |
invincible --version |
| uv tool | uv tool upgrade invincible-ai |
invincible --version |
| editable checkout | git pull && pip install -e . |
invincible --version |
invincible update runs the correct pip command for pip installs (--check
for a dry run, --yes for scripted upgrades). It refuses pipx, uv,
editable, and container installs and prints the command you should use
instead, so it can never corrupt a managed environment.
login, connect, and doctor print a one-line notice when a newer
release is on PyPI (at most one check per 24h, cached under
~/.invincible/). Disable it with INVINCIBLE_NO_UPDATE_CHECK=1. The check
is a read-only GET to pypi.org — no account or machine data is sent.
After any upgrade: self-hosters run invincible db upgrade (migrations are
never automatic), and always-on agents restart with
invincible harness service restart.
Quick Start
A. Use the hosted service (one install command)
pip install -U invincible-ai
invincible connect # first run: browser opens → sign in or register → Approve
Pairing registers your account on https://invincible-ai.me and saves the
minted key to ~/.invincible/config.json. Then, in the dashboard:
- Providers — connect your own provider keys (BYOK).
- MCP connector — add
https://invincible-ai.me/mcpto Claude (or any MCP client) and approve the client when the browser asks.
With the agent running, a remote AI can read/write files and run commands
on your machine, under your account's approvals. Prefer raw API access
instead? Mint an inv_ key (dashboard → Account → API keys) and call the
gateway directly:
export INVINCIBLE_BASE=https://invincible-ai.me
export INVINCIBLE_API_KEY=inv_... # dashboard -> Account -> API keys
curl $INVINCIBLE_BASE/v1/chat/completions \
-H "Authorization: Bearer $INVINCIBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hello!"}]}'
Every account is independent: the same commands work for every user with
their own inv_ key, their own connected provider credentials, and their own
sessions — no account can see or route through another's.
B. Run your own server (operators / self-hosters — users never do this)
invincible setup --db-url postgresql://user:pass@db-host:5432/invincible
invincible db upgrade # create/migrate the schema (explicit, never auto-run)
invincible start # http://127.0.0.1:8000 (dev loopback)
invincible start --host 0.0.0.0 # reachable from other machines
invincible setup writes missing secret values (INVINCIBLE_OWNER_SECRET)
as random secrets.token_urlsafe(32) tokens, generates the BYOK credential
master key (INVINCIBLE_CREDENTIAL_KEY), and takes the INVINCIBLE_DB_URL
via --db-url (non-interactive) — preserving your existing .env comments
and values. INVINCIBLE_OWNER_SECRET signs account browser sessions
(dashboard login, OAuth consent) — not something /mcp requests send.
For a real host — TLS, $PORT, proxy headers, the two-role database split,
the container start command (0.0.0.0:$PORT), and the go-live checklist —
follow docs/DEPLOYMENT.md. Development-only database
shortcuts are covered in docs/CONFIGURATION.md.
Clients of your own server point at it explicitly:
invincible connect --server https://mycompany.ai (or
ANTHROPIC_BASE_URL=https://mycompany.ai for Claude Code). The hosted
service is the CLI default, so your users pass no flag at all.
See Examples for ready-to-run curl calls, or continue reading
for the full configuration, API, and tooling reference.
Configuration
Everything is environment variables plus one YAML file — no other config.
.env variables
| Variable | Required by | Purpose |
|---|---|---|
INVINCIBLE_DB_URL |
startup (required since Phase 16) | PostgreSQL DSN for all persistent state. Use a managed/reachable PostgreSQL on a remote deployment, e.g. `postgresql+asyncpg://[...] |
INVINCIBLE_MIGRATE_DB_URL |
container/platform deploys | Schema-owner DSN used only for the one db upgrade the image runs at startup (falling back to INVINCIBLE_DB_URL when unset), so[...] |
INVINCIBLE_OWNER_SECRET |
account sessions | Signs account browser sessions (dashboard login, OAuth consent). Not sent on /mcp — requests use short-lived OAuth Bearer tokens. **If uns[...] |
INVINCIBLE_CREDENTIAL_KEY |
BYOK | Fernet master key encrypting stored provider credentials at rest. Generated by invincible setup (or invincible secret credential-key); back it up ��[...] |
INVINCIBLE_PERSIST_PENDING_ACTIONS |
startup | Opt-in: when set, staged execute_bash/write_file approvals are written to the PostgreSQL database (pending_actions table) and survive [...] |
INVINCIBLE_AGENT_ROUTING |
startup (required on public multi-user deployments) | Routes confirmed tool execution to the caller's paired harness agent (invincible harness connect) instea[...] |
INVINCIBLE_AGENT_ROOT |
agent | Sandbox root for the local agent (default: the user's home directory). Reads and writes outside it are blocked; .env*, .git, .ssh, SSH keys, *.pem, `*c[...] |
/v1/* requests authenticate with per-user inv_ API keys (minted on
the dashboard's Account page, or by the host with
invincible api-key create --user <email-or-id>). Each user connects their
own provider credentials on the dashboard's Providers page (BYOK) and
routes only through them — there is no shared gateway key and no shared
provider pool.
The secrets are independent: a leaked /mcp URL alone is not enough to
reach tool execution (a live OAuth bearer token is required as well), and
rotating one secret never affects the other.
providers.yaml
The packaged invincible/providers.yaml is a static fixture (tests and
direct Router construction); live traffic never reads it — every
/v1/* request routes through the caller's own connected BYOK
credentials. There is no repository-root copy.
Full reference — schema, validation rules, timeout resolution: docs/CONFIGURATION.md. How to add a provider, aliases, and supported shapes: docs/PROVIDERS.md.
CLI Commands
Two commands, both exposed as invincible and inv. Most users only
need the first two rows (the hosted service); the rest is self-host and
server administration:
| Command | Purpose |
|---|---|
invincible login [--server URL] |
Pair this machine with an Invincible server (device flow): opens the approval page in your browser — click Approve and the command finishes, saving the inv_ key to ~/.invincible/config.json. Defaults to the hosted service (https://invincible-ai.me); pass --server for a self-hosted or local server. URL + code are printed for headless terminals; the Account page also has a "Pair a device" box for typing a code by hand. |
invincible connect |
Keep this machine online. First run pairs automatically (browser opens, you click Approve). Runs confirmed jobs on this machine with your own account — nothing listens for inbound connections. Ctrl+C to stop. |
invincible status |
Check this machine: account, online state, next step. Same as harness status. |
invincible harness setup |
Advanced: pair this machine and print its MCP connector config (idempotent — never re-pairs silently). Most users need only login + connect. |
invincible harness connect |
Advanced: same as connect. |
invincible harness status |
Advanced: same as status. |
invincible harness service install |
Write an always-on service definition (systemd/launchd/schtasks) so the machine stays online across reboots. |
invincible harness service restart |
Restart the installed always-on service (the post-upgrade step that makes the new version actually run). |
invincible update |
Install the latest invincible-ai release from PyPI (--check for a dry run, --yes for scripts). Detects pip/pipx/uv/editable/container installs and prints the right command instead of corrupting a managed environment. |
invincible setup |
Create/update .env (non-interactive, scriptable): generates missing secrets (token_urlsafe(32), never echoed), generates the BYOK credential master key, preserves exist[...] |
invincible secret rotate |
Generate a brand-new INVINCIBLE_OWNER_SECRET and rewrite it in place — no manual .env editing, never echoes the value (unless --show). Preserves every other[...] |
invincible start |
Start the server. --host (default 127.0.0.1; pass 0.0.0.0 to be reachable from other machines), --port (default 8000), --reload, --log-level, --env-file, `-[...] |
invincible doctor |
Environment/config diagnostics: providers.yaml, secrets, and PostgreSQL connectivity + schema revision (DSN always password-masked); loud FAIL on a stale/unmanaged schema.[...] |
invincible dev-db |
Provision or verify a local Postgres development database (Docker fallback included) and print/write a working INVINCIBLE_DB_URL. Loopback-only and dev-credential by[...] |
invincible db upgrade |
Run the packaged Alembic migrations to head against INVINCIBLE_DB_URL. Explicit by design — nothing auto-migrates. |
invincible oauth list |
Show registered OAuth clients, their redirect URIs, and active/revoked grants. |
invincible oauth revoke <client_id> |
Revoke every access/refresh token for a client immediately. |
invincible oauth test-client |
Headless helper: registers a client, approves it, and prints a ready-to-use Bearer token + curl for /mcp (no browser needed). |
invincible api-key create --user <id-or-email> --label L |
Mint an API key (inv_…) under a named account (host tool) — raw key shown once, only its SHA-256 hash is stored. |
invincible api-key list |
List API keys by visible prefix (never hashes or raw keys). |
invincible api-key revoke <id-or-prefix> |
Revoke a key immediately. |
invincible users list |
List accounts (host tool; roles are informational only). |
invincible users reset-password <email> |
Reset an account's password (host recovery path — database access is the proof of authority; --generate prints a strong password once). Every bro[...] |
invincible setup --force
invincible secret rotate # new owner secret, in place
invincible secret rotate --show # ...and print it (rarely needed)
invincible start --port 9000 --config ./my-providers.yaml
Full CLI reference: docs/CONFIGURATION.md → CLI reference.
API
Endpoints
| Method | Path | Auth | Purpose |
|---|---|---|---|
GET |
/ |
none | Health check → {"status": "healthy"} |
HEAD |
/ |
none | 200 OK — Claude Code's base-URL probe |
GET |
/health |
none | Service detail → {"service", "status", "version"} |
GET |
/v1/models |
Authorization: Bearer inv_… |
OpenAI-compatible model list built from your connected credentials (empty when you have none) |
POST |
/v1/chat/completions |
Bearer inv_… API key |
OpenAI chat completion routed through your own credentials with failover |
POST |
/v1/messages |
Bearer inv_… API key |
Anthropic Messages API (same routing) |
POST |
/v1/responses |
Bearer inv_… API key |
OpenAI Responses API for Codex CLI (same routing) |
Chat request
- Body:
{"messages": [...], "stream": false}— OpenAI message format.messages,stream, andmodelare accepted.modelis a soft routing hint (matches a configured alias or exactmodel_id; unknown names are ignored). Other OpenAI fields are rejected with 422. - Streaming:
stream: truereturns an OpenAI-compatible Server-Sent Events (text/event-stream) response. Each event is achat.completion.chunk(data: {…}\n\n), and the stream ends withdata: [DONE]. Chunks are forwarded from the upstream provider as they arrive — nothing is buffered. Providers that fail before the first chunk trigger the normal failover; an error after streaming has begun terminates the stream with a well-formeddata: {"error": …}event. - Sessions: history is loaded from PostgreSQL keyed by the
X-Session-Idheader (defaultdefault), prepended to your messages, and the assistant reply is persisted back.session_idis a partition key, not a credential. For streamed responses the reply is reconstructed from the chunk deltas and saved once the stream completes. - Response: the upstream provider's JSON is forwarded verbatim (non-streaming).
Anthropic Messages (POST /v1/messages)
Invincible also speaks the Anthropic Messages API, so Claude Code and other Anthropic-native clients work without modification:
# .env for Claude Code (or your shell):
# No /v1 suffix — Claude appends /v1/messages itself.
ANTHROPIC_BASE_URL=http://127.0.0.1:8000
ANTHROPIC_AUTH_TOKEN=inv_... # older Claude Code: ANTHROPIC_API_KEY instead
Claude Code probes HEAD /, then calls POST /v1/messages?beta=true — both
are served. Supported request fields: model, system, messages,
max_tokens, stream. Everything else Claude Code sends (tools,
tool_choice, metadata, temperature, top_p, top_k,
stop_sequences, unknown fields, anthropic-beta / anthropic-version
headers, the ?beta=true query) is accepted and ignored — never a 422.
The model field overrides each of your connected credentials'
stored default in auto routing: the request's model is sent verbatim
upstream to every credential in your order (check
GET /v1/models — it lists exactly the model ids your key can route
to). A model none of your providers serves fails with the provider's
own "not a valid model" error, surfaced as an Anthropic
invalid_request_error — set /model to one exact id from
/v1/models, or omit model to use each credential's stored default.
Provider slugs are exact: deepseek-v4.1-flash-free and
deepseek-v4.1-flash:free are different models — a near-miss fails
upstream with "not a valid model".
In chain/pinned routing each step carries its own model and the
request model only picks the entry point. The response reports the
model that actually served, so a fallback across models stays visible
instead of being masked by an echo of what you asked for.
- Streaming:
stream: truereturns Anthropic SSE events in the canonical order —message_start→content_block_start→content_block_delta(one per text delta) →content_block_stop→message_delta→message_stop.tool_usecontent blocks are preserved and streamed as structured events (content_block_start+input_json_deltaframes) withstop_reason: "tool_use"at the end;tool_resultblocks in the request are carried asrole: "tool"messages, so tool-shaped conversations round-trip losslessly (ids preserved).imagecontent blocks are still skipped. A mid-stream upstream failure emits a well-formed Anthropicerrorevent and closes — never malformed SSE. - Sessions: the same
X-Session-Idheader and PostgreSQL store are used, and history is serialized in the shared internal format — an OpenAI client and a Claude Code session on the same id see the same conversation. - Errors: mapped to Anthropic error types (
invalid_request_error,authentication_error,permission_error,not_found_error,rate_limit_error,api_error,overloaded_error) with sanitized messages; upstream provider bodies are never forwarded. - Unsupported today: image content (skipped during conversion).
Status codes
| Status | When |
|---|---|
200 |
Upstream success — JSON body forwarded verbatim, or SSE stream (stream: true) |
400 |
Caller has no connected provider credentials (BYOK) — connect one on the dashboard's Providers page |
401 |
Missing/invalid inv_ API key |
422 |
Body fails validation (missing messages, extra fields) |
4xx |
Upstream returned a non-failover error (e.g. 400) — forwarded verbatim |
503 |
All of the caller's credentials failed or are in cooldown (before streaming starts) |
The Anthropic endpoint uses the same statuses; error bodies are Anthropic
shaped ({"type": "error", "error": {"type": …, "message": …}}) and map to
Anthropic error types.
Full contract — sessions, trimming, timeout semantics: docs/API_REFERENCE.md.
MCP Support
POST /mcp implements a minimal JSON-RPC 2.0 subset: initialize,
tools/list, and tools/call. Protocol version: 2025-06-18.
- Auth: OAuth 2.1 + PKCE via the built-in authorization server. Clients
discover it at
/.well-known/oauth-protected-resource(RFC 9728), register at/oauth/register, get owner approval on the/oauth/authorizeconsent page, then sendAuthorization: Bearer <access_token>on every/mcprequest. Wrong/missing/expired/revoked token →401with aWWW-Authenticate: Bearer resource_metadata="…"challenge. (NoX-MCP-Secretheader anymore; theMCP_SHARED_SECRETenv var is retired and inert.) - Notifications: a request without an
idstill runs its side effect but the server replies204 No Contentwith no body.
Tools
| Tool | Arguments | Confirmation | Gate |
|---|---|---|---|
read_file |
path |
No | Blocks only real secrets/state: .env*, sessions.db, .git/. Allows invincible/, tests/, providers.yaml. |
execute_bash |
command + a confirm_action token round-trip |
Yes — staged with a token; runs only after confirm_action(token, approve=true) (30s execution timeout) |
Blocks high-b[...] |
write_file |
path, content + a confirm_action token round-trip |
Yes — staged with a token; writes only after confirm_action(token, approve=true) |
Blocks writes to .env*, `pr[...] |
confirm_action |
token, approve |
— | Approves/denies a pending execute_bash/write_file; token is single-use and expires after 10 minutes. |
Security model, full denylist inventory, and known limits: docs/SECURITY.md.
Run tools on your own PC (the local agent)
On a hosted deployment with INVINCIBLE_AGENT_ROUTING=1, confirmed tool
actions execute on your machine, not the server — the security
checks (denylist, staging, approval tokens) all stay server-side, but
the work travels to a paired local agent. From zero to "my AI just ran a
command on my PC" is two commands — no account to create first, no
separate pairing step:
pip install -U invincible-ai
invincible connect # first run: browser opens → sign in or register → Approve
On first run the harness pairs the machine itself: the browser opens on
the approval page (create your account right there if you don't have
one, then click Approve), the minted key is saved to
~/.invincible/config.json, and the relay connects straight into its
WS-first loop — it never asks you to run another command first. Every
later start is just invincible connect again; pairing happens once per
machine, ever.
Self-hosters point at their own server once:
invincible connect --server https://mycompany.ai (or
--server http://127.0.0.1:8000 against a local invincible start).
invincible login remains as the explicit re-pair/repair tool.
Then connect Claude/Grok/any MCP client to https://your-server.example.com/mcp
as usual. While the agent is running, its console shows each dispatched
job; the dashboard MCP page shows a live Agent: online/offline
badge. The agent sandbox is your home directory (INVINCIBLE_AGENT_ROOT
to override), with .env*, .git, .ssh, and key material blocked
everywhere. An offline agent means tool calls answer agent_offline
immediately — nothing hangs. Full transport and threat model:
docs/MCP_PROTOCOL.md and
SECURITY.md §10.
Provider Routing
Every /v1/* request routes through the caller's own connected BYOK
credentials (dashboard → Providers), in the order the user configured
(auto by ability, or an explicit pinned/chain order). Per attempt:
| Upstream status | Router behavior |
|---|---|
200 |
record_success (resets cooldown) → return body |
429 / 5xx |
record_failure → cooldown → try next credential |
401 / 403 |
Skip that credential for this request → try next |
Other 4xx (e.g. 400) |
Abort — forward the provider's status and body |
| Network error | record_failure → cooldown → try next credential |
| In cooldown | Skipped silently (log only) |
All of the caller's credentials exhausted → HTTP 503. No credentials
connected at all → HTTP 400. Cooldowns follow
30 * 2**(failures-1), capped at 300s; all health state is in-memory and
resets on restart.
Deep dive (failover state machine, context trimming): docs/ARCHITECTURE.md.
Examples
Every call below uses $INVINCIBLE_BASE — the hosted service, or your own
server:
export INVINCIBLE_BASE=https://invincible-ai.me # or http://127.0.0.1:8000 locally
export INVINCIBLE_API_KEY=inv_... # dashboard -> Account -> API keys
1. Health check
curl $INVINCIBLE_BASE/
# {"status": "healthy"}
2. List models
curl $INVINCIBLE_BASE/v1/models \
-H "Authorization: Bearer $INVINCIBLE_API_KEY"
# {
# "object": "list",
# "data": [
# {"id": "<your connected credentials' model ids>", "object": "model", "owned_by": "invincible"},
# {"id": "<your configured aliases>", "object": "model", "owned_by": "invincible"}
# ]
# }
The list is built from your connected BYOK credentials, so it reflects exactly what the gateway can route to for you (an empty list when you have none connected). Real model ids are listed first, then the aliases you configured.
3. Chat with session memory
curl $INVINCIBLE_BASE/v1/chat/completions \
-H "Authorization: Bearer $INVINCIBLE_API_KEY" \
-H "Content-Type: application/json" \
-H "X-Session-Id: my-conversation" \
-d '{"messages": [{"role": "user", "content": "Hello!"}]}'
The assistant reply is stored under my-conversation and will be included in
your next request with the same X-Session-Id — the model remembers the
conversation.
4. Stream a chat (SSE)
curl -N $INVINCIBLE_BASE/v1/chat/completions \
-H "Authorization: Bearer $INVINCIBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "Hello!"}], "stream": true}'
-N (aka --no-buffer) prints each event as it arrives. Tokens are streamed
as OpenAI-compatible chat.completion.chunk events:
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1783161600,"model":"gemini-2.5-flash","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1783161600,"model":"gemini-2.5-flash","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","created":1783161600,"model":"gemini-2.5-flash","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]
5. Use it from Claude Code (Anthropic)
ANTHROPIC_BASE_URL=https://invincible-ai.me claude # or your own server URL
Claude Code probes HEAD /, then calls POST /v1/messages with streaming.
You can send the same call directly:
curl $INVINCIBLE_BASE/v1/messages \
-H "Authorization: Bearer $INVINCIBLE_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"claude-sonnet-4","max_tokens":1024,
"messages":[{"role":"user","content":"Hello!"}]}'
And stream it (stream: true) to receive Anthropic SSE events ending in
message_stop.
6. List MCP tools
First get an MCP access token. On the hosted service, add the connector in
your MCP client at $INVINCIBLE_BASE/mcp and approve it in the browser —
the client then holds the token. On a local/self-hosted server the
headless helper registers a client against that server's database and
prints a ready-to-use Bearer token:
invincible oauth test-client --env-file .env # prints a token + curl example
export ACCESS_TOKEN=...
curl -X POST $INVINCIBLE_BASE/mcp \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
7. Run a command via MCP
curl -X POST $INVINCIBLE_BASE/mcp \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call",
"params":{"name":"execute_bash","arguments":{"command":"git status"}}}'
The call returns a pending_confirmation result carrying a token. To
approve it, call confirm_action with that token (or deny with
approve: false):
curl -X POST $INVINCIBLE_BASE/mcp \
-H "Authorization: Bearer $ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":3,"method":"tools/call",
"params":{"name":"confirm_action",
"arguments":{"token":"<token from step 2>","approve":true}}}'
The command runs (or the file is written) only after approval; the token is single-use and expires after 10 minutes.
8. Reach it from a cloud AI
On a deployed server the plain HTTPS URL is the entry point: point the MCP
client at https://your-domain/mcp (or https://invincible-ai.me/mcp on the
hosted service) and approve the connector in the browser.
A laptop has no public URL, so invincible start starts a Cloudflare tunnel
alongside the server by default: cloudflared tunnel run <name> (name
defaults to invincible, override with --tunnel-name or
INVINCIBLE_TUNNEL_NAME). cloudflared's log lines (and the public URL when
cloudflared prints one) appear prefixed [tunnel]; a tunnel that dies is
reported as soon as it exits, and it is shut down with the server. To skip
the tunnel, pass --no-tunnel.
For a one-off quick tunnel instead (no named-tunnel config required):
cloudflared tunnel --url http://127.0.0.1:8000
# → https://random-name.trycloudflare.com — call /mcp on this URL
Tunnel or not, the URL alone is useless without an access token — and any
valid token can be revoked immediately with invincible oauth revoke <client_id>.
More MCP protocol details: docs/MCP_PROTOCOL.md.
Architecture
┌──────────────────────────────────┐
OpenAI-compatible │ invincible/main.py │
agent ─── /v1/chat ──► │ (FastAPI) │
Claude Code │ compat/ │
(Anthropic) ─ /v1/msg ►│ openai_compat ──────► anthropic │
Codex ─ /v1/resp►│ responses_compat │
│ │ mcp │ dashboard │ agent │ │
Cloud AI ─── /mcp ─►│ │ core/chat_service.py │
(via tunnel) │ │ core/router.py (BYOK failover)│
│ │ core/tool_executor (denylist) │
└──────┬──────────────┬────────────┘
│ │
┌─────────────▼──┐ ┌───────▼────────────┐
│ core/router.py │ │ core/tool_executor │
│ tiered failover│ │ (denylist + approval)│
│ + ctx trimming │ └─────────┬──────────┘
└───────┬────────┘ │ confirmed jobs
│ ┌───────────▼────────────┐
│ │ user's paired machine │
┌─────────────▼──────────▼──────────►│ (agent/runner.py) │
│ PostgreSQL stores └────────────────────┘
│ (sessions/memory/continuity/BYOK) │
└────────────────────────────────────┘
The compatibility layers (OpenAI, Anthropic, Responses) only translate;
all three produce the same internal message model, which is what the
shared chat pipeline (core/chat_service.py), the Router, the session
store, and the trimming logic consume.
Package layout
| Path | Role |
|---|---|
invincible/main.py |
FastAPI app, lifespan, auth dependencies, router wiring, HEAD / and /health. |
invincible/endpoints/openai_compat.py |
POST /v1/chat/completions (JSON + SSE streaming, session merge + upstream call); GET /v1/models. |
invincible/endpoints/anthropic_compat.py |
POST /v1/messages; translates Anthropic ↔ internal model, calls the same Router. |
invincible/endpoints/responses_compat.py |
POST /v1/responses (OpenAI Responses protocol for Codex CLI). |
invincible/endpoints/dashboard.py |
Jinja2 + HTMX dashboard (overview, sessions, tasks, memory, usage, settings) — session-cookie realm only. |
invincible/endpoints/accounts.py |
/auth/*, /projects, /api-keys, device pairing, GitHub login (session realm). |
invincible/endpoints/byok.py |
Per-user provider-credential management (connect, test, order, routing config). |
invincible/endpoints/agents.py |
Agent transport: /agent/poll + /agent/result, WS relay, machine inventory. |
invincible/endpoints/docs.py |
Public docs site (/docs). |
invincible/models/anthropic.py |
Pydantic request model: only real fields declared; everything else ignored. |
invincible/compat/common.py |
Protocol-neutral internal-message/usage helpers shared by compat layers. |
invincible/compat/anthropic.py |
Pure Anthropic translators: flattening, finish-reason map, error map, Anthropic SSE streaming. |
invincible/endpoints/mcp.py |
POST /mcp; JSON-RPC 2.0 dispatch, tools/list, tools/call. |
invincible/core/router.py |
Tiered failover over per-user BYOK credentials, response trimming, timeouts. |
invincible/core/provider_health.py |
Per-credential failure counts + exponential cooldowns. |
invincible/core/db.py |
SQLAlchemy engine factory + schema metadata (single source of truth). |
invincible/migrations/ |
Packaged Alembic environment (invincible db upgrade). |
invincible/core/session_store.py |
Conversation memory on PostgreSQL, partitioned by session id. |
invincible/core/tool_executor.py |
Denylists, pending-action approval (confirm_action), tool execution. |
invincible/core/chat_service.py |
Shared chat pipeline (history, memory, continuity, routing) used by /v1/chat/completions and the dashboard webchat, so API and web sessions share history. [...] |
invincible/agent/runner.py |
The local agent on the user's machine: pairing config + poll/WS loop + home-confined sandbox. |
invincible/cli.py |
Click CLI: setup/start(+tunnel)/login/connect/harness/update/doctor/dev-db/db/secret/oauth/api-key/users. |
invincible/providers.yaml |
Static provider fixture (tests/direct construction; live traffic is BYOK-only). |
Documentation
| Doc | What it covers |
|---|---|
| docs/ARCHITECTURE.md | Module map, request flows, context-trimming deep dive, failover state machine. |
| docs/API_REFERENCE.md | The /v1/chat/completions contract: request, response, status codes, failover semantics. |
| docs/CONFIGURATION.md | .env variables, providers.yaml schema, timeouts, database options, CLI reference. |
| docs/DEPLOYMENT.md | Running it remotely: required env vars, ports/TLS/proxy headers, two-role database, migrations, single-instance constraints, go-live checklist. |
| docs/PROVIDERS.md | Adding providers, the full schema, model aliases, auth types, supported shapes, troubleshooting. |
| docs/MCP_PROTOCOL.md | Client-facing /mcp spec: JSON-RPC shape, tools, notifications, hosted URL vs. self-host tunnel. |
| docs/SECURITY.md | Threat model, auth realms, denylist inventory, approval flow, known limits. |
| docs/TESTING.md | How tests work, fixtures, per-file coverage map. |
| docs/RELEASING.md | Cutting a release: versioning, the build gate, the tag-triggered PyPI workflow. |
| docs/ROADMAP.md | Current platform direction, a verified snapshot of what is implemented, and the phased plan (identity, isolation, accounts, memory/context intelligence, das[...] |
Known limits (tl;dr)
- Invincible translates Anthropic tool calls correctly (
tool_use→tool_calls,tool_result→role: "tool"messages, ids preserved, and responses close withstop_reason: "tool_use"), but it does not execute the tools itself — execution is the client's job (Claude Code runs the tool and sends backtool_result). - Image content blocks are skipped during flattening.
- Denylists are text-pattern matches, not shell parsers — wrappers like
powershell -Commandcan smuggle commands past them; the token approval step is the real safety boundary. - Remote approval — approval goes through
/mcpitself: whoever holds a valid OAuth Bearer token can approve pending actions; there is no terminal prompt and no separate human-authentication surface. Revoke the client withinvincible oauth revoke <client_id>to cut that off. - Sessions are stored plaintext in PostgreSQL (protect the DSN); cooldowns and provider disables are in-memory only. Since the multi-tenant audit, every store path is ownership-scoped per principal — one user can never read another's sessions, graph, or history, and the former operator override is gone.
- In-memory server state. Provider cooldowns, staged approvals (unless
INVINCIBLE_PERSIST_PENDING_ACTIONSis set), and the agent registry live in the process, so a remote deployment runs a single instance (no horizontal autoscaling) and clients simply retry across a restart — see docs/DEPLOYMENT.md.
Full details: docs/SECURITY.md → Known limits.
Development
pip install -e ".[dev]"
pytest
See docs/TESTING.md.
Metadata
Release files for invincible-ai 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| invincible_ai-0.6.1.tar.gz | 968.6 kB | With provenance | Details for invincible_ai-0.6.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| invincible_ai-0.6.1-py3-none-any.whl | Python 3 | none | any | Details for invincible_ai-0.6.1-py3-none-any.whl |
Total release size: 1.6 MB
Release files / invincible_ai-0.6.1.tar.gz
| Download URL | invincible_ai-0.6.1.tar.gz |
|---|---|
| Size | 968.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56ef5e9aaa219af14ad578388656dac8c51aa703fa6bf3b05f7d7117cf8daaa3
|
|
BLAKE2b-256 checksum How to use checksums |
ca33959f2830cdb1974fe39fdefdf297302454f1a7846da856852fbf86cab4a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logRelease files / invincible_ai-0.6.1-py3-none-any.whl
| Download URL | invincible_ai-0.6.1-py3-none-any.whl |
|---|---|
| Size | 636.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a5972016368f047fc00e9e0211caeb65e4bed10daa1b43b1461ffd603f523254
|
|
BLAKE2b-256 checksum How to use checksums |
12e1104cc934888a28e981c169304c3a87e9878027532f0fdf11cfd6ffec36d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logSecurity for invincible-ai 0.6.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for invincible_ai-0.6.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.