Architecture
How requests are routed to Azure and Amazon Bedrock, metered, and recorded.
Draftworks exposes an OpenAI-compatible API backed by Azure and Amazon Bedrock. A shared model catalog defines model IDs, provider routing, supported endpoints, token limits, and pricing.
Request path
- The gateway resolves the requested model and checks endpoint compatibility.
- Convex authenticates the API key and atomically reserves credits for the request.
- Azure requests use the provider's OpenAI-compatible API. Claude Chat Completions requests are translated into Anthropic's native Bedrock request format.
- The gateway normalizes the public model ID, meters provider usage, and signs a receipt over the model ID, token counts, and request and response hashes.
- Convex records usage and content logs, releases the reservation, and debits the prepaid balance. Duplicate usage submissions with the same request ID do not debit twice.
For streaming requests, the gateway splits the upstream stream. One branch serves the client; a second branch continues metering even if the client disconnects. Failed connections release their reservation without charging tokens that were not reported.
Provider routing
GPT-6 Astra uses Azure. Grok 4.6, Kimi K3, and GLM 5.3 also use Azure, alongside the existing models. Claude Fable 5.1, Fable 5, Opus 5, and Sonnet 5 use app-specific Amazon Bedrock inference profiles in us-west-2.
Vercel authenticates to AWS with an OIDC role restricted to the Draftworks project and model resources. No long-lived AWS access key is deployed with the app. Global Bedrock profiles can route inference across AWS regions; x-draftworks-upstream-region reports the source region.
Draftworks never silently substitutes a different model. A signed receipt records Draftworks' statement about the response; it is not an independent model attestation from Azure, AWS, or the model developer.
Storage and billing
All money uses integer nano-USD: one billion units equal one dollar. Cache reads, cache writes, long-context premiums, and image or audio token rates are accounted for before the tier discount. Historical events retain their recorded costs when catalog rates change.
Convex stores accounts, API key hashes, usage events, credit balances, receipts, and bounded request and response content logs. See data handling.
The realtime relay remains at realtime.draftworks.dev. It meters the session's provider usage events through the same credit ledger. See realtime.
How receipts prevent bait-and-switch
The structural problem with discounted inference, and how signed receipts make silent model substitution a provable fraud rather than a suspicion.
Security
Key custody, transport security, infrastructure boundaries, and how to reach us — security reports, abuse, and DPA requests.