IBEX Harness
DocsBenchmarksBlogChangelogRoadmap
GitHub
IBEX Harness

Documentation

HTTP route inventoryAuth gRPC (ValidateToken, ValidateAgent)Health and metricsChat completionsErrors
API Reference›Chat completions
API Reference

Chat completions

OpenAI-compatible POST /v1/chat/completions — auth, validation, provider forward, and optional Idempotency-Key replay.

The proxy exposes an OpenAI-shaped chat endpoint for SDK drop-in compatibility. After auth, agent verification, rate limits, and request normalization, the proxy forwards to the configured LLM provider (mock or live).

Endpoint

POST/v1/chat/completions

OpenAI-compatible chat completions. Gateway alias: POST /proxy/v1/chat/completions (same handler).

Decision records: ADR-0012 (normalization), ADR-0035 (Idempotency-Key). Path org_id on org-scoped probes must match the token org.

Required headers

ParameterTypeDescription
AuthorizationRequiredstring
Bearer PAT issued by auth service.
X-IBEX-Agent-IDRequiredstring (uuid)
Calling agent; must belong to the token organization.
Content-TypeRequiredstring
Must be application/json (charset suffix allowed).

Optional headers

ParameterTypeDescription
Idempotency-Keystring
Opaque client key (max 256 chars). Within TTL (default 24h), the same key + same request fingerprint replays the first completion without a second upstream call. Redis key: idempotency:{org_id}:{key} (org from token). See ADR-0035.
X-IBEX-Session-IDstring
Sticky session external id (max 64 chars). Missing/invalid values are minted and echoed on the response. Durable sessions require POSTGRES_DSN — see Sessions.

Idempotency behavior

  • Missing header: unchanged — every request calls the provider.
  • Hit (same key + fingerprint): replay stored HTTP status and body; no provider call; no second session checkpoint / trace.
  • Conflict (same key, different body): 409 with IDEMPOTENCY_KEY_REUSE.
  • In progress: 409 with IDEMPOTENCY_IN_PROGRESS — retry after a short backoff.
  • Transient upstream errors (429 / 5xx): pending claim is released so the same key can retry.
  • Streaming: stream=true with Idempotency-Key → 400 VALIDATION_ERROR (non-streaming only in this milestone).
  • Redis down / timeout: fail-open — request proceeds without dedupe (billing risk under Redis outage).
  • The key is not forwarded to OpenAI.

Request body (parsed fields)

Per ADR-0012, the proxy decodes OpenAI-shaped JSON and ignores unknown top-level keys:

ParameterTypeDescription
modelRequiredstring
Model identifier (validated in ADR-0013; max 256 chars).
messagesRequiredarray
Objects with role and content strings; max 1000 messages.
streamboolean
Optional OpenAI fields (temperature, max_tokens) also parsed. Idempotency-Key requires stream=false.

After successful parse, the proxy logs metadata only (org_id, request_id, model, message_count, stream) — never message content.

Response

Successful non-streaming completions return the upstream OpenAI-shaped JSON with status from the provider. Response headers include X-Request-ID, X-Trace-ID, and X-Response-Time per ADR-0013. Session sticky header X-IBEX-Session-ID may be set when session lifecycle is enabled.

Mapped provider failures use the stable error envelope (PROVIDER_TIMEOUT, RATE_LIMITED, etc.).

Try it locally

bash
IDEM_KEY="$(uuidgen)"
BODY='{"model":"gpt-4o","messages":[{"role":"user","content":"hello"}]}'
curl -s -w "\nHTTP %{http_code}\n" \
  -X POST http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer ${IBEX_DEV_TOKEN}" \
  -H "X-IBEX-Agent-ID: ${IBEX_DEV_AGENT_ID}" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ${IDEM_KEY}" \
  -d "${BODY}"
# Retry with the same key + body to verify replay (no second upstream completion):
curl -s -w "\nHTTP %{http_code}\n" \
  -X POST http://localhost:8080/v1/chat/completions \
  -H "Authorization: Bearer ${IBEX_DEV_TOKEN}" \
  -H "X-IBEX-Agent-ID: ${IBEX_DEV_AGENT_ID}" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: ${IDEM_KEY}" \
  -d "${BODY}"

With IBEX_LLM_MODE=mock, expect HTTP 200 and an OpenAI-shaped JSON body. The second request reuses the same Idempotency-Key and body so replay can be verified without a second upstream completion.

1

Auth + agent verify

ValidateToken and ValidateAgent over gRPC before body handling completes.

2

Parse + validate JSON

OpenAI-shaped body normalized per ADR-0012/0013.

3

Idempotency claim (optional)

When Idempotency-Key is set, claim or replay via Redis (ADR-0035).

4

Provider forward

Mock or live Complete; commit idempotency record on terminal response.

Related

  • HTTP route inventory — all implemented proxy paths
  • Sessions — sticky X-IBEX-Session-ID
  • Quickstart — five-minute local path
  • Authentication — header requirements
  • ADR-0035 — Idempotency-Key design

Was this page helpful?

Edit on GitHub

Last updated on

PreviousHealth and metricsNextErrors

On this page

  • Endpoint
  • Required headers
  • Optional headers
  • Idempotency behavior
  • Request body (parsed fields)
  • Response
  • Try it locally
  • Related
0%