x402 AI Inference API
Call DGrid inference with x402 payment requirements. The first request returns payment instructions; the second request includes a signed x-payment header and executes inference.| Base URL | https://api.dgrid.ai |
| Authorization | Content-Type: application/json; x-payment: <x402-payment-payload> |
| Request | application/json |
| Response | 402 / 200 · application/json or text/event-stream |
Payment and Authentication
This endpoint uses the x402 payment protocol instead of an account balance workflow. Required request headers for the paid request:Request Body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
messages | array | Yes | - | UIMessage array containing role and content. |
model | string | No | anthropic/claude-opus-4.5 | Target model name. |
stream | boolean | No | true | Whether to return a streaming response. |
temperature | number | No | 1 | Sampling temperature. |
topP | number | No | 1 | Top-p sampling parameter. |
topK | number | No | 40 | Top-k sampling parameter. |
Response Modes
stream = true (default)
Returns UIMessageStream SSE (text/event-stream) using AI SDK style UIMessageChunk events. Common event types include:
starttext-starttext-deltatext-endfinish
finish event includes messageMetadata such as:
totalTokensallowanceLeftcalculatedPriceWeirealPriceWei
stream = false
Returns a single JSON response in DGrid’s standard completion format with choices and usage.
Errors
| Status | Meaning |
|---|---|
402 | Payment validation failed, usually because the first request omitted x-payment or the payment signature was invalid |
400 | Invalid request or upstream validation error |
500 | Server-side or upstream provider error |
Settlement Notes
- The endpoint settles based on actual usage.
- If actual cost exceeds the authorized upper bound, settlement is capped at that authorized limit.

