Surface
Supported endpoints
A readable snapshot of what's live in the worker, grouped by capability.
Source of truth: worker/src/index.js
supported_endpoints
app.get('/v1/api-tokens')
app.post('/v1/api-tokens')
app.delete('/v1/api-tokens/:tokenId')
app.get('/v1/usage')
app.get('/v1/usage/daily')
app.get('/v1/usage/rollups')
app.all('/v1/chat/completions')
app.all('/v1/ocr')
app.all('/v1/chroma')
app.all('/v1/chroma/*')
Notes: methods shown match the worker's route registration.
API Tokens
Manage API tokens (requires platform JWT; API tokens are not allowed here).
3 routes
- GET /v1/api-tokensList API tokens for the current user.Headers
- Authorization : Bearer <platform_jwt> Required.
Responsedataarray · Token records for the current user.Notes- Requires a platform JWT; API tokens are rejected here.
- POST /v1/api-tokensCreate a new API token.Headers
- Authorization : Bearer <platform_jwt> Required.
- Content-Type : application/json Required.
Bodynamestring · Optional token display name.scopesstring[] · Optional; must be an array of strings.Responseidstring · Token id.tokenstring · Returned once at creation time....any · Additional token metadata.Notes- Requires a platform JWT; API tokens are rejected here.
- DELETE /v1/api-tokens/:tokenIdRevoke an API token.Headers
- Authorization : Bearer <platform_jwt> Required.
Path paramstokenIdstring · Token id to revoke.Responsestatus204 · No content on success.Notes- Requires a platform JWT; API tokens are rejected here.
LLM Gateway
OpenAI-compatible chat completions proxy (streaming supported).
1 routes
- POST /v1/chat/completionsProxy to upstream `/v1/chat/completions`.Headers
- Content-Type : application/json Required.
- Authorization : Bearer <token> Required only when API_AUTH_REQUIRED=1.
- OpenAI-Organization : <org_id> Optional; forwarded to upstream.
- OpenAI-Project : <project_id> Optional; forwarded to upstream.
Bodymodelstring · Required by upstream; logged for analytics.messagesarray · Required by upstream.streamboolean · If true, worker injects stream_options.include_usage=true.stream_options.include_usageboolean · Forced to true when stream=true.max_completion_tokensnumber · Logged for analytics.max_tokensnumber · Logged for analytics (fallback).temperaturenumber · Logged for analytics.top_pnumber · Logged for analytics....any · Other OpenAI Chat Completions fields are passed through.ResponsestreamSSE · When stream=true, returns text/event-stream frames.usageobject · Included in-stream when streaming; present in JSON response otherwise....any · Upstream response (pass-through).Notes- Only POST is supported; other methods return 405.
- Upstream is configured via OPENAI_BASE_URL / OPENAI_API_BASE (defaults to api.openai.com).
OCR
OCR proxy backed by Mistral OCR.
1 routes
- POST /v1/ocrProxy to upstream `/v1/ocr`.Headers
- Content-Type : application/json Required.
- Authorization : Bearer <token> Required only when API_AUTH_REQUIRED=1.
Bodydocumentobject · If provided, passed through to upstream.documentsarray · If provided, passed through to upstream.urlstring · If provided (and no document[s]), worker converts to document:{type:'url',url}.modelstring · Optional; if url is used and model is missing, worker sets it from MISTRAL_OCR_MODEL....any · Other upstream OCR fields are passed through.Response...any · Upstream OCR response (pass-through).Notes- Only POST is supported; other methods return 405.
- Upstream is configured via MISTRAL_BASE_URL / MISTRAL_API_BASE (defaults to api.mistral.ai).
- Model default: MISTRAL_OCR_MODEL (defaults to mistral-ocr-latest).
Chroma
Chroma proxy with per-user namespacing.
2 routes
- ALL /v1/chromaProxy to Chroma base URL.Headers
- Authorization : Bearer <token> Required when API_AUTH_REQUIRED=1; required for user namespacing.
- x-chroma-api-key : <injected> Default auth header; worker injects CHROMA_API_KEY.
- CHROMA_AUTH_HEADER : <optional> Override injected auth header name (default x-chroma-api-key).
- CHROMA_AUTH_SCHEME : <optional> If set, worker prefixes the api key (e.g. 'Bearer').
Bodydatabasestring · If JSON body includes database, worker prefixes it with user namespace.namestring · For specific POST create-database paths, worker prefixes name with user namespace....any · All other fields are passed through.Notes- Upstream is configured via CHROMA_BASE_URL / CHROMA_API_BASE; worker requires CHROMA_API_KEY.
- Namespace is derived from authenticated user id; requests without user context are rejected.
- Namespace separator is configurable via CHROMA_NAMESPACE_SEPARATOR (defaults to '__').
- ALL /v1/chroma/*Proxy to Chroma with path passthrough.Headers
- Authorization : Bearer <token> Required when API_AUTH_REQUIRED=1; required for user namespacing.
- x-chroma-api-key : <injected> Default auth header; worker injects CHROMA_API_KEY.
Query*any · Query string is passed through (with database name prefixed when present).Notes- Everything after /v1/chroma is forwarded to the Chroma base URL.
- Worker prefixes database names in both the path and query string for per-user isolation.
Usage
Analytics Engine powered usage summaries.
3 routes
- GET /v1/usageUsage summary (top models/paths/types/providers).Headers
- Authorization : Bearer <usage_key> Optional; required only when USAGE_API_KEY is set.
- x-usage-key : <usage_key> Optional alternative to Authorization header.
Queryhoursint · Optional; 1..720. Overrides days.daysint · Optional; converted to hours. Used only if hours is missing.Responsewindow.hoursnumber · Effective window size.window.generated_atstring · ISO timestamp.totalsobject · Requests, errors, token totals, OCR totals, avg latency, etc.totals.ocr_pagesnumber · Aggregated OCR pages (unknown page counts contribute 0).totals.ocr_estimated_cost_usdnumber · Aggregated OCR estimated cost in USD.top_modelsarray · Top models by requests.top_pathsarray · Top paths by requests.by_typearray · Rollup by request_type.by_type[].ocr_pagesnumber · OCR pages by request type.by_type[].ocr_estimated_cost_usdnumber · OCR estimated cost by request type.by_providerarray · Rollup by provider.Notes- If USAGE_API_KEY is not set, this endpoint does not require a key.
- Requires Analytics Engine credentials: CLOUDFLARE_ACCOUNT_ID + CLOUDFLARE_API_TOKEN (or CF_* / ACCOUNT_ID / API_TOKEN).
- Dataset can be overridden via ANALYTICS_DATASET (defaults to ai_worker_requests).
- Dashboard defaults to 7-day aggregates via ?days=7.
- GET /v1/usage/dailyDaily usage buckets for charting (UTC).Headers
- Authorization : Bearer <usage_key> Optional; required only when USAGE_API_KEY is set.
- x-usage-key : <usage_key> Optional alternative to Authorization header.
Querydaysint · Optional; defaults to 7 for dashboard usage.Responsegenerated_atstring · ISO timestamp.timezonestring · UTC timezone label for day boundaries.daysnumber · Number of day buckets returned.daily[]array · Ordered oldest-to-newest day buckets.daily[].datestring · UTC calendar date (YYYY-MM-DD).daily[].requestsnumber · Daily request count.daily[].input_tokensnumber · Daily input tokens.daily[].output_tokensnumber · Daily output tokens.daily[].total_tokensnumber · Daily total tokens.daily[].input_estimated_cost_usdnumber · Daily estimated input-token cost in USD.daily[].output_estimated_cost_usdnumber · Daily estimated output-token cost in USD.daily[].estimated_cost_usdnumber · Daily estimated cost in USD.daily[].ocr_pagesnumber · Daily OCR pages.daily[].ocr_estimated_cost_usdnumber · Daily OCR estimated cost in USD.Notes- If USAGE_API_KEY is not set, this endpoint does not require a key.
- Missing days should be zero-filled server-side for stable chart rendering.
- GET /v1/usage/rollupsWindowed rollups (10m, 1h, 6h, 24h, 7d).Headers
- Authorization : Bearer <usage_key> Optional; required only when USAGE_API_KEY is set.
- x-usage-key : <usage_key> Optional alternative to Authorization header.
Responsegenerated_atstring · ISO timestamp.rollups[]array · Primary rollup entries containing label + totals.rollups[].windowstring · Preset label (10m, 1h, 6h, 24h, 7d).rollups[].totals.ocr_pagesnumber · OCR pages for the rollup window.rollups[].totals.ocr_estimated_cost_usdnumber · OCR estimated cost for the rollup window.windows[]array · Compatibility alias for rollups[].Notes- If USAGE_API_KEY is not set, this endpoint does not require a key.
- Requires Analytics Engine credentials: CLOUDFLARE_ACCOUNT_ID + CLOUDFLARE_API_TOKEN (or CF_* / ACCOUNT_ID / API_TOKEN).
Examples
Quick starts
chat_completions curl
curl -sS https://<your-worker-domain>/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $FOURTY32_TOKEN" \
-d '{
"model": "openai/gpt-4.1",
"messages": [{"role":"user","content":"Plan a launch checklist"}]
}' usage curl
curl -sS https://<your-worker-domain>/v1/usage?days=7 \
-H "Authorization: Bearer $USAGE_KEY"