IBEX Harness
DocsBenchmarksBlogChangelogRoadmap
GitHub
IBEX Harness

Documentation

OverviewConfigurationAuthenticationAuth cachingDirectivesSessionsRate limitingRequest routingProvider adapters
Proxy›Request routing
Proxy

Request routing

How requests are normalized and forwarded to provider adapters.

The proxy exposes an OpenAI-compatible chat completion endpoint and diagnostic auth probes. Every chat request is parsed, validated, and authenticated end-to-end, then routed to the mock or live provider (ADR-0012, ADR-0013).

Org scope from token

POST /v1/chat/completions does not include org_id in the URL. Tenant scope comes from the validated PAT. Path-based org probes exist only on /v1/orgs/{org_id}/auth-probe.

Protected routes

POST/v1/chat/completions

OpenAI-compatible chat completions. Requires ProxyChatCompletion permission. Mock mode returns 200; unknown models return 501.

GET/v1/internal/auth-probe

Diagnostic route returning org_id and permissions from the bearer token.

GET/v1/orgs/{org_id}/auth-probe

Diagnostic route with explicit path org; must match token org.

Middleware chain for chat

Mermaid diagram: flowchart LR
+-----------+     +-------------+     +------+     +-------------+     +-----------+     +-----------+     +----------------+     +---------+
|           |     |             |     |      |     |             |     |           |     |           |     |                |     |         |
| bodyLimit |---->| contentType |---->| auth |---->| agentVerify |---->| rateLimit |---->| chatParse |---->| providerRouter |---->| handler |
|           |     |             |     |      |     |             |     |           |     |           |     |                |     |         |
+-----------+     +-------------+     +------+     +-------------+     +-----------+     +-----------+     +----------------+     +---------+

Global middleware (metrics, request ID, logging) wraps all routes. Chat-specific middleware runs in the order above — auth never executes on oversize or wrong Content-Type bodies. chatParse attaches the validated body; providerRouter attaches the selected provider.Provider (or returns 501 PROVIDER_NOT_CONFIGURED).

Normalization pipeline

1

Body size gate

Payloads over IBEX_MAX_REQUEST_BODY_BYTES (default 1 MiB) return 413 before JSON parse.

2

Content-Type gate

POST bodies must be application/json; otherwise 415.

3

JSON parse

Malformed JSON returns 400 INVALID_JSON with request_id in the envelope.

4

Semantic validation

Required fields (model, messages) produce field_errors array per ADR-0013.

5

Provider handoff

ProviderRoutingMiddleware resolves model → adapter; unknown models return 501 PROVIDER_NOT_CONFIGURED. Handler forwards via context provider.

Minimal valid body

JSON
{
  "model": "gpt-4o",
  "messages": [
    { "role": "user", "content": "Hello" }
  ]
}

Validation error example

HTTP 400 with structured field errors:

JSON
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Request validation failed",
    "request_id": "0192a3b4-c5d6-7890-abcd-ef1234567890",
    "timestamp": "2026-06-14T12:00:00Z",
    "field_errors": [
      {
        "field": "model",
        "code": "REQUIRED",
        "message": "model is required"
      }
    ]
  }
}

Optional docs_url appears when IBEX_ERROR_DOCS_BASE is configured — links to API errors.

Send a routed request

bash
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" \
  -d '{"model":"gpt-4o","messages":[{"role":"user","content":"ping"}]}'

Default mock mode expected: HTTP 200 for registered models. 501 PROVIDER_NOT_CONFIGURED means the model is not in the registry.

Path org enforcement

On /v1/orgs/{org_id}/auth-probe, the path parameter must be a valid UUID and must equal the organization embedded in the validated token. Cross-tenant attempts return 403 — never 404 — per Security authentication.

ScenarioHTTPCode
Invalid UUID in path400INVALID_PATH_ORG
Token org A, path org B403PATH_ORG_MISMATCH
Matching org200—

Request correlation

Every response includes:

  • X-Request-ID — propagated to auth gRPC as x-request-id metadata
  • X-Trace-ID — OpenTelemetry trace
  • X-Response-Time — handler duration

Use request_id from JSON errors to grep proxy and auth logs during integration debugging. See Request lifecycle.

Phase 2 forwarding

When a provider adapter registers, the handler will:

  1. Select adapter by model prefix or org configuration
  2. Attach org/agent metadata for audit and tracing
  3. Stream OpenAI-compatible SSE or JSON back to the client

See Provider adapters for mock vs live configuration and roadmap for remaining exit-gate work.

Related

  • Authentication — credentials required before routing
  • Provider adapters — Phase 2 upstream contract
  • Overview — full endpoint table
  • Chat completions — request shape and headers

Was this page helpful?

Edit on GitHub

Last updated on

PreviousRate limitingNextProvider adapters

On this page

  • Protected routes
  • Middleware chain for chat
  • Normalization pipeline
  • Minimal valid body
  • Validation error example
  • Send a routed request
  • Path org enforcement
  • Request correlation
  • Phase 2 forwarding
  • Related
0%