docs / api-reference

API reference

The wire contract for sending events to PromptConduit: envelopes, batches, OpenTelemetry, errors and retries.

The REST API lives at https://api.promptconduit.dev. Its main ingest endpoint is POST /v1/events/raw, which takes schema-2 event envelopes from the CLI. POST /v1/events/raw/batch sends up to 100 at once. Errors follow RFC 7807. The other public endpoints are listed under Other endpoints.

Most people never call the API by hand: the CLI builds envelopes from your AI tool's hooks and sends them for you. This page documents the wire contract so you can debug what the CLI sends, or send events from a tool or exporter the CLI doesn't cover.

Authentication

Every endpoint on this page needs an API key, sent as a bearer token in the Authorization header. Keys start with sk_. The web app's sign-in tokens are accepted too. /health, /openapi.json and /v1/ping need no key.

http
Authorization: Bearer sk_your_api_key_here

There are two ways to get a key:

  • From the CLI. promptconduit login (or the promptconduit init wizard) runs a browser device flow and saves a key to ~/.config/promptconduit/config.json. Add --no-browser to print the verification URL instead of opening it.
  • From the web app. Your profile page at app.promptconduit.dev/profile lists your keys and lets you create and revoke them. The full key is shown once, at creation; afterwards only its prefix is displayed.

To give an existing key to the CLI, run promptconduit config set --api-key-stdin < key.txt, then promptconduit test to check connectivity. See Configuration for environments and the config file. A missing, revoked, or expired key returns 401. Treat keys like passwords: anyone holding one can write events to your account.

POST /v1/events/raw

The primary ingest endpoint. Used by the CLI to forward raw events from AI tools. The server applies tool-specific adapters to normalize events into the canonical schema.

The CLI does no transformation of the tool's payload. It wraps the hook JSON exactly as the tool emitted it in raw_event, adds metadata and locally computed context, and posts it. The same envelope is also the line written to ~/.promptconduit/events.jsonl on your machine, so promptconduit events lets you inspect captured envelopes before anything is sent.

Request (JSON — envelope schema v2)

json
{
  "schema": 2,
  "event_id": "019f2850-1234-7000-8000-abcdefabcdef",
  "session_id": "9a402796-…",
  "prompt_id": "e28d55f7-…",
  "tool": "claude-code",
  "hook_event": "UserPromptSubmit",
  "captured_at": "2026-07-03T18:00:00Z",
  "cli_version": "0.9.0",
  "raw_event": { /* raw hook JSON from the AI tool, untouched */ },
  "enrichments": {
    "env":   { "host": "laptop", "os": "darwin", "arch": "arm64", "cwd": "/Users/you/my-project" },
    "trace": { "trace_id": "4bf9…", "span_id": "00f0…" },
    "vcs":   {
      "type": "github",
      "repo": "you/my-project",
      "repo_url": "https://github.com/you/my-project",
      "branch": "main",
      "commit": { "hash": "abc123", "message": "feat: x", "author": "You" },
      "dirty": false,
      "remote_url": "[email protected]:you/my-project.git"
    },
    "prompt": { "count": 3, "chars": 120, "words": 22 }
  }
}

Envelope fields

FieldTypeRequiredDescription
schemanumberYesEnvelope generation. Must be 2 or higher; older envelopes are rejected with 400.
event_idstringYesUnique id for the event. The CLI uses a UUIDv7 (time-ordered). Used for deduplication; see Idempotency and retries.
toolstringYesWhich AI tool produced the event. See Tool values.
hook_eventstringYesThe hook that fired, as the tool names it (e.g. UserPromptSubmit, PostToolUse, beforeSubmitPrompt). Must be a string; may be empty.
captured_atstringYesISO 8601 / RFC 3339 timestamp of capture, in UTC.
cli_versionstringYesVersion of the producer that built the envelope. Non-empty.
raw_eventany JSONYesThe tool's native hook payload, untouched.
session_idstringNoSession id lifted from the raw payload (for Cursor, conversation_id). Omit when the tool doesn't report one.
prompt_idstringNoPrompt id lifted from the raw payload (for Cursor, generation_id).
enrichmentsobjectNoSlug-keyed map of locally computed context. Must be an object, not an array.
attachmentsarrayNoAttachment metadata for multipart uploads. See below.

enrichments is an extensible slug-keyed map of normalized context computed by the CLI (e.g. vcs, cost, prompt). Every slug is optional and unknown slugs are stored verbatim and ignored by readers, so new enrichments require no API change. Envelopes with schema < 2 are rejected.

The well-known slugs are:

  • env: host, OS, architecture and working directory.
  • trace: trace and span ids.
  • vcs: repository, branch, commit, dirty state, and the pull request when known.
  • prompt: prompt count, characters and words, on prompt-submit hooks only.
  • cost: tokens and USD per request, with totals.

The CLI also adds others such as diff, tools, permission, subagent, and turn. If you build envelopes yourself, you can send none of them; the event is still accepted.

Tool values

These are the tool values the CLI sends. Each matches the slug used by promptconduit install (see Supported Tools).

toolSourceServer-side normalization
claude-codeClaude CodeYes
cursorCursorYes
gemini-cliGemini CLI (experimental)Yes
grokGrok Build (experimental)Yes
codexOpenAI Codex CLI (experimental)Stored raw
copilotGitHub Copilot CLI (experimental)Stored raw

Any non-empty string is accepted. When no adapter exists for the tool, the envelope is still stored and the response status is stored_raw_only instead of processed.

Response

A JSON envelope is normally accepted for processing and returns 202 Accepted with status: "queued". The event is stored durably before the response is sent and usually shows up in the app within seconds:

http
HTTP/1.1 202 Accepted
Content-Type: application/json
X-Request-ID: …

{
  "event_id": "019f2850-1234-7000-8000-abcdefabcdef",
  "status": "queued",
  "message": "Accepted for processing",
  "raw_r2_key": "…"
}

The server may instead process the event immediately (always for multipart uploads) and return 201 Created with the final status:

http
HTTP/1.1 201 Created
Content-Type: application/json
X-Request-ID: …

{
  "event_id": "019f2850-1234-7000-8000-abcdefabcdef",
  "status": "processed"
}

Treat both 201 and 202 as success.

statusMeaning
queued202 only. Accepted for processing; usually visible within seconds. Duplicates are detected during processing, so a resend of a known event_id may also return queued.
processedStored and normalized by the tool's adapter.
stored_raw_onlyStored, but not normalized (no adapter for this tool, or this hook isn't one the adapter tracks). A message field explains.
skippedOne of two cases, and the message says which. An event with this event_id was already ingested, so nothing was written. Or the event is older than the retention window, so a raw copy was stored but isn't counted.

The body may include additional reference fields. Rely only on event_id, status, and message.

Example with curl

bash
curl -sS https://api.promptconduit.dev/v1/events/raw \
  -H "Authorization: Bearer $PROMPTCONDUIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "schema": 2,
    "event_id": "019f2850-1234-7000-8000-abcdefabcdef",
    "session_id": "9a402796-5c1e-4c1a-9a51-0d7f3c2b8e11",
    "tool": "claude-code",
    "hook_event": "UserPromptSubmit",
    "captured_at": "2026-07-03T18:00:00Z",
    "cli_version": "my-exporter/1.0",
    "raw_event": {
      "session_id": "9a402796-5c1e-4c1a-9a51-0d7f3c2b8e11",
      "hook_event_name": "UserPromptSubmit",
      "cwd": "/Users/you/my-project",
      "permission_mode": "default",
      "prompt": "Add a retry to the upload client"
    },
    "enrichments": {
      "prompt": { "count": 1, "chars": 32, "words": 7 }
    }
  }'

Generate a fresh event_id for every distinct event. Reusing one makes the server treat the new event as a duplicate.

Multipart upload (with attachments)

When the event contains attachments (images, documents), the CLI sends a multipart request:

http
POST /v1/events/raw
Authorization: Bearer sk_your_api_key_here
Content-Type: multipart/form-data; boundary=---boundary

-----boundary
Content-Disposition: form-data; name="envelope"

{ ...envelope JSON, including:
  "attachments": [{
    "attachment_id": "5f0c6b2e-8d1a-4e7b-9c3f-2a6d1e4b7c90",
    "filename": "screenshot.png",
    "content_type": "image/png",
    "size_bytes": 48213,
    "type": "image"
  }] }

-----boundary
Content-Disposition: form-data; name="attachment[5f0c6b2e-8d1a-4e7b-9c3f-2a6d1e4b7c90]"; filename="screenshot.png"
Content-Type: image/png

<binary data>
-----boundary--
  • The envelope field carries the envelope JSON as a string.
  • Each file goes in a field named attachment[<attachment_id>], where the id matches an entry in the envelope's attachments array. A file with no matching metadata fails the request.
  • Every metadata entry needs attachment_id, filename, content_type, a positive size_bytes, and type set to image, document, or file.
  • The limit is 50 MB per attachment. If any attachment fails, none are kept and the request returns 400.

POST /v1/events/raw/batch

Sends several envelopes in one request, which is cheaper than one request per event when you have a backlog (for example, replaying an outbox). Each envelope uses the same schema-2 format as POST /v1/events/raw. Attachments aren't supported here; send events with attachments to the single-event endpoint as multipart.

Request

http
POST /v1/events/raw/batch
Authorization: Bearer sk_your_api_key_here
Content-Type: application/json

{
  "events": [
    { "schema": 2, "event_id": "019f2850-1234-7000-8000-abcdefabcdef", ... },
    { "schema": 2, "event_id": "019f2850-1235-7000-8000-abcdefabcdef", ... },
    { "schema": 2, "tool": "claude-code" }
  ]
}
  • The body is a JSON object with an events array of 1 to 100 envelopes.
  • The whole body must be 1 MB or smaller.

Response

A batch that was taken in returns 202 Accepted. Accepted events are processed in the background and usually show up within seconds:

http
HTTP/1.1 202 Accepted
Content-Type: application/json

{
  "accepted": 2,
  "rejected": [
    { "index": 2, "error": "Invalid envelope: Missing event_id, ..." }
  ]
}
FieldMeaning
acceptedHow many events were accepted for processing. Duplicates of an already-ingested event_id count as accepted.
rejectedEvents that failed validation, each with its index (position in events, from 0) and an error message. accepted plus the number of rejected entries equals the number of events sent.

A rejected event is a permanent failure, such as a missing field or an invalid captured_at. Don't resend it unchanged; one bad event never fails the rest of the batch.

Status codes for /v1/events/raw/batch

Statustype suffixWhenRetry?
202—Batch taken in. See accepted and rejected.Never resend rejected events.
400validation-errorBody isn't valid JSON, has no events array, or the array is empty.No. Fix the request.
401authentication-errorMissing, revoked, or expired API key.After fixing the key.
413validation-errorMore than 100 events, or a body larger than 1 MB.Split into smaller batches.
503service-unavailableA temporary server-side failure affected at least one valid event. Sends Retry-After.Yes: resend the whole batch after Retry-After.

Resending a whole batch after a 503 is safe: events are deduplicated by event_id, so any that already got through are not counted twice.

Idempotency and retries

The server deduplicates on event_id, so retrying after a timeout or dropped connection is always safe. A resend of an event that was already stored returns 202 (status: "queued", dropped as a duplicate during processing) or 201 with status: "skipped":

http
HTTP/1.1 201 Created
Content-Type: application/json

{
  "event_id": "019f2850-1234-7000-8000-abcdefabcdef",
  "status": "skipped",
  "message": "Duplicate event_id — already ingested"
}

Events whose captured_at is more than 90 days old are accepted, so clients don't keep resending them, but aren't counted in analytics or cost. They return status: "skipped". Don't backfill events older than that.

Deduplication needs an id of 16–64 characters from [0-9a-zA-Z_-] (a UUID qualifies). Any other value is replaced with a server-generated id, which means retries of that event are no longer deduplicated.

What the CLI does on failure:

  • Sends happen in a detached background process, so the AI tool never waits on the network.
  • Fast failures on 429, 500, 502, 503, or a refused or reset connection are retried up to twice, with jittered delays of about 0.5 s and 2 s. A Retry-After of up to 10 s is honored. Timeouts and 504 are not retried.
  • If the send still fails with no response, 401, 403, 408, 429, or any 5xx, the envelope is queued in a local outbox and replayed after a later send succeeds. Run promptconduit events flush to replay it now. Other 4xx responses are permanent and the envelope is not retried.

If you write your own client, follow the same rule: retry 429 and 5xx with backoff, honor Retry-After, and don't retry 400.

OTLP / OpenTelemetry

Export traces and logs from Claude Code, Cursor, or any OTLP-compatible agent directly to PromptConduit. OTLP data lands in the same event store as CLI envelopes, under the same account. For Claude Code, the Claude Code Telemetry guide has the full setup; its api_request events count toward team cost.

shell
export OTEL_EXPORTER_OTLP_ENDPOINT=https://api.promptconduit.dev/v1/otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer sk_your_api_key_here"

Endpoints: POST /v1/otlp/v1/traces, POST /v1/otlp/v1/logs, and POST /v1/otlp/v1/metrics. Bodies may be OTLP/HTTP protobuf (application/x-protobuf) or JSON (application/json), optionally with Content-Encoding: gzip; gRPC is not served. Any other content type returns 415, and a body that doesn't decode returns 400. Metrics are accepted and discarded so all three signals can be enabled safely. A successful export returns 200 with an empty response in the request's encoding ({} for JSON).

Error format

Errors follow RFC 7807. They are returned with Content-Type: application/problem+json and always carry type, title, status, and detail, plus instance (the request path) and request_id. The same request id is in the X-Request-ID response header; include it when you report a problem. Branch on type or status, not on detail, which is human-readable and may change.

http
HTTP/1.1 401 Unauthorized
Content-Type: application/problem+json

{
  "type": "https://api.promptconduit.dev/errors/authentication-error",
  "title": "Authentication Error",
  "status": 401,
  "detail": "API key required",
  "instance": "/v1/events/raw",
  "request_id": "…"
}

Status codes for /v1/events/raw

Statustype suffixWhenRetry?
202—Accepted for processing (status: "queued").—
201—Processed immediately: stored, or skipped as a duplicate.—
400validation-errorThe body isn't valid JSON, or an envelope field is missing or has the wrong type. Also when schema is below 2, the multipart form has no envelope field, or an attachment is invalid or over 50 MB.No. Fix the request.
401authentication-errorMissing, revoked, or expired API key.After fixing the key.
500internal-errorUnexpected server failure.Yes, with backoff.
503service-unavailableTransient storage error before the event was committed. Sends Retry-After.Yes, after Retry-After.

Every type is the prefix https://api.promptconduit.dev/errors/ plus the suffix. A validation error lists every problem it found in detail:

http
HTTP/1.1 400 Bad Request
Content-Type: application/problem+json

{
  "type": "https://api.promptconduit.dev/errors/validation-error",
  "title": "Validation Error",
  "status": 400,
  "detail": "Invalid envelope: Unsupported envelope schema (need schema >= 2); v1 envelopes are no longer accepted — upgrade the CLI, Missing raw_event",
  "instance": "/v1/events/raw",
  "request_id": "…"
}

A transient failure tells you when to retry, in both the header and the body:

http
HTTP/1.1 503 Service Unavailable
Content-Type: application/problem+json
Retry-After: 2

{
  "type": "https://api.promptconduit.dev/errors/service-unavailable",
  "title": "Service Unavailable",
  "status": 503,
  "detail": "Temporary storage error; retry the request",
  "instance": "/v1/events/raw",
  "request_id": "…",
  "retry_after": 2
}

Other endpoints

EndpointAuthWhat it's for
GET /openapi.jsonNoneAn OpenAPI 3.1 description of /v1/events/raw and the team, billing and personal cost routes the web app and CLI use. The batch, OTLP and CI routes aren't in it yet.
GET /healthNoneHealth check.
POST /v1/ci/jobsAPI keyGitHub Actions job metadata from promptconduit ci sync, priced and matched to agent sessions.
POST /v1/pingNoneThe CLI's anonymous daily usage ping. See Usage ping.
/mcpOAuthThe remote MCP server, with OAuth at /oauth/* and discovery under /.well-known/. See AI agents (MCP).

When to use the API directly vs the CLI

Use the CLI for Claude Code and Cursor (and, with --experimental, Gemini CLI, Codex, Copilot CLI, and Grok Build). promptconduit install <tool> wires up the hooks, and the CLI adds git, cost, and trace enrichments, uploads attachments, writes a local log, and handles retries and the outbox. You also get the free local features (cost, sessions, local skills) with no account. See the Quick Start and the CLI Reference.

Use the API directly when the CLI can't run where events happen, such as a hosted agent or a CI job without the binary. Or when you're building an integration for a tool the CLI doesn't support yet. If your agent already emits OpenTelemetry, point its OTLP exporter at /v1/otlp and skip envelopes entirely. Either way, you're responsible for minting unique event_ids and retrying safely.

If you only want local cost tracking in your editor, you don't need the API at all: the editor extension reads the local event log.

Next steps