klanex API guide
Everything you need to run agent tool calls through klanex. Base URL: https://api.klanexai.com · auth header: X-API-Key · machine-readable spec: openapi.yaml
Sandbox: https://api.sandbox.klanexai.com runs the same code with Stripe in test mode — sign up there with a test card and integrate without touching production. Accounts, API keys, and data are separate per environment, and sandbox data carries no durability promise. Create a sandbox account →
Quickstart
- Sign up — verify your email, put a card on file, and save the
api_keyandwebhook_secretshown once. - Submit your first execution:
curl -s https://api.klanexai.com/v1/executions \
-H "X-API-Key: klx_…" -H "Content-Type: application/json" \
-d '{
"target": { "url": "https://httpbingo.org/post", "method": "POST" },
"payload": { "amount": 42 },
"payload_schema": { "type": "object",
"properties": { "amount": { "type": "number" } },
"required": ["amount"] },
"idempotency_key": "demo-1"
}'
# → 202 {"execution_id": "exe_…", "status": "QUEUED"}
- Poll
GET /v1/executions/{id}(or receive a signed webhook) and watch it in the dashboard.
Execution lifecycle
klanex answers in milliseconds and executes asynchronously. Statuses:
PENDING_APPROVAL → QUEUED → RUNNING → RETRYING (loops) → SUCCEEDED | FAILED
Retryable target failures (429, 5xx, timeouts) are absorbed with exponential backoff and per-host circuit breakers. Permanent rejections (4xx) fail fast with a correction hint for your agent.
Submit an execution
POST /v1/executions
| Field | Meaning |
|---|---|
target.url, target.method | The third-party call to make. Default method POST. |
target.headers | Credentials for the target. Encrypted at rest (Cloud KMS); never readable again, redacted in all reads. |
target.connection_id | Use a vault connection instead of raw headers. |
target.timeout_ms | Per-attempt timeout. |
payload | The JSON body your agent produced. Stored byte-exact for replay. |
payload_schema | JSON Schema gate. Invalid payloads bounce with 422 + llm_hint — feed it back to your model and resubmit. |
callback_url | Where to POST the signed result webhook. |
max_attempts | Retry budget. |
idempotency_key | Same key → same execution returned (200 + X-Klanex-Idempotent-Replay: true), never a duplicate run. |
requires_approval | Pause in PENDING_APPROVAL until a human decides — in the dashboard or right from Slack. |
Read & list
GET /v1/executions/{id} — full state; credentials always redacted.
GET /v1/executions?status=&since=&until=&limit=&cursor= — newest first, cursor-paginated.
Human-in-the-loop approvals
POST /v1/executions/{id}/approve · POST /v1/executions/{id}/reject (optional {"reason": "…"})
Executions submitted with requires_approval wait in PENDING_APPROVAL. Rejection is terminal (APPROVAL_REJECTED). Replays of gated executions pause again — approvals never carry over. With Slack connected, approvals are one button click.
Replay
POST /v1/executions/{id}/replay — re-run a terminal execution with its byte-exact original payload and sealed credentials; the clone records replay_of for audit.
POST /v1/replays {"since": "…", "until": "…"} — bulk-replay failures after an outage; permanently rejected payloads are skipped.
Webhooks
On terminal state klanex POSTs to your callback_url:
{
"event": "execution.completed", // or "execution.failed"
"execution_id": "exe_…",
"status": "SUCCEEDED",
"attempts": 2,
"result": { "status_code": 200, "body": "{…}" },
"error": null
}
| Header | Meaning |
|---|---|
X-Klanex-Signature | sha256= + hex HMAC-SHA256 of "<timestamp>.<body>" keyed with your webhook_secret |
X-Klanex-Timestamp | Unix seconds used in the signature — reject stale values to prevent replay |
X-Klanex-Event | Event name |
X-Klanex-Execution-Id | Execution ID |
Respond 2xx; 5xx responses are retried 3 times with backoff. Both SDKs ship a verifyWebhook / verify_webhook helper.
Error codes
Codes are part of the contract — feed llm_hint back to your agent so it can self-correct.
| Code | Terminal? | Meaning |
|---|---|---|
SCHEMA_INVALID | yes (422 at submit) | Payload failed your schema — fix and resubmit. |
TARGET_TIMEOUT | retried | Target didn't answer in time. |
TARGET_RATE_LIMITED | retried | Target returned 429. |
TARGET_UNAVAILABLE | retried | Target 5xx / connection failure. |
TARGET_REJECTED | yes | Target 4xx — retrying won't help; correct the request. |
CIRCUIT_OPEN | retried | Host breaker open; klanex waits it out. |
ATTEMPTS_EXHAUSTED | yes | Retry budget spent. |
APPROVAL_REJECTED | yes | A human said no. |
CONNECTION_UNAUTHORIZED | yes | Vault connection can't mint a valid token — reauthorize it. |
RATE_LIMITED | 429 at submit | Your tenant rate limit; honor Retry-After. |
Token vault (connections)
Store credentials once, reference them by ID — agents never see raw secrets, and OAuth tokens refresh automatically.
POST /v1/connections create
GET /v1/connections list (never returns secrets)
DELETE /v1/connections/{id} remove
GET /v1/connections/{id}/authorize begin OAuth consent (browser)
- static_bearer — bring your own long-lived token.
- oauth2_client_credentials — machine-to-machine; klanex fetches and refreshes.
- oauth2_authorization_code — browser consent; presets for GitHub, Google, Slack, HubSpot, Salesforce, Stripe.
Then submit with "target": {"url": "…", "connection_id": "con_…"} — the worker injects a fresh token at execution time.
Slack & Jira integrations
Slack — approval buttons + failure alerts
- Create a Slack app (
api.slack.com/apps→ From scratch). - Incoming Webhooks → activate → add to a channel → copy the
hooks.slack.comURL. - Basic Information → copy the Signing Secret.
- Interactivity & Shortcuts → ON → Request URL:
https://api.klanexai.com/integrations/slack/actions
curl -X PUT https://api.klanexai.com/v1/integrations/slack \
-H "X-API-Key: klx_…" -H "Content-Type: application/json" \
-d '{"webhook_url":"https://hooks.slack.com/services/…",
"signing_secret":"…","notify_on_failure":true}'
Gated executions post Approve/Reject buttons; clicks are verified with Slack's request signature and recorded in the audit trail. Payload contents never appear in Slack.
Jira — auto-file issues on failures
curl -X PUT https://api.klanexai.com/v1/integrations/jira \
-H "X-API-Key: klx_…" -H "Content-Type: application/json" \
-d '{"base_url":"https://yourco.atlassian.net","email":"you@yourco.com",
"api_token":"…","project_key":"OPS","issue_type":"Task"}'
Every terminally failed execution files an issue with the error and replay instructions — never the payload. Check state with GET /v1/integrations; remove with DELETE /v1/integrations/slack or …/jira.
Credential rotation
POST /v1/api-key/rotate — new key returned once; the old key stops working immediately.
POST /v1/webhook-secret/rotate — callbacks after rotation are signed with the new secret; update your verifier.
Both are also one click in the dashboard under Credentials.
MCP server
Agents can drive klanex over the Model Context Protocol instead of raw REST. The /mcp endpoint (Streamable HTTP) lives on the same hosts as the API:
| Endpoint | Environment | Keys |
|---|---|---|
https://api.klanexai.com/mcp | production | klx_live_… |
https://api.sandbox.klanexai.com/mcp | sandbox (free) | klx_test_… |
Authenticate with the same API key, sent as either an X-API-Key header or Authorization: Bearer klx_… (for clients that can only set an Authorization header). Add it to Claude Code:
claude mcp add --transport http klanex https://api.klanexai.com/mcp \
--header "X-API-Key: klx_live_…"
For stdio-only clients (e.g. Claude Desktop), use the npm shim — it proxies to the hosted endpoint and routes klx_test_… keys to the sandbox automatically:
{
"mcpServers": {
"klanex": {
"command": "npx",
"args": ["-y", "klanex-mcp"],
"env": { "KLANEX_API_KEY": "klx_live_…" }
}
}
}
Six tools are exposed. They proxy to the REST endpoints above in-process, so validation, the schema gate, quota, rate limits, idempotency, and credential sealing behave identically — and errors surface as tool errors carrying the same llm_hint, so the agent self-corrects.
| Tool | Does |
|---|---|
execute | Submit an intent; optional wait_seconds (≤55) blocks for the terminal result. |
get_execution | Status, attempts, result, or classified error for one execution. |
list_executions | The account's executions, filterable by status and time, paginated. |
replay_execution | Re-run a terminal execution byte-exact — outage recovery without re-prompting. |
get_usage | Plan and current-month usage/quota. |
list_connections | Stored credential connections to reference via connection_id. |
SDKs
- TypeScript / Node — github.com/chrassy/klanex-js: zero-dep client, webhook verification, key rotation.
- Python — github.com/chrassy/klanex-python: sync + async clients, webhook verification, plus
klanex.adaptersfor LangChain, CrewAI, and Google ADK.
Or plain HTTP from anything else — the whole surface is in openapi.yaml.