x402 API Reference
This page documents the x402-specific endpoint details for DGrid pay-per-inference requests.
If you are looking for provider-style request patterns such as OpenAI-compatible or Claude-compatible payloads, see Model API. Those references remain the best source for provider-specific invocation examples. This page focuses on the x402 payment flow plus the shared inference fields exposed at the x402 endpoint.
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.
/x402/v1Payment and Authentication
This endpoint uses the x402 payment protocol instead of an account balance workflow.
Required request headers for the paid request:
Content-Type: application/json
x-payment: <x402-payment-payload>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
The final 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.
