Skip to content

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.

POST
https://api.dgrid.ai
POST/x402/v1
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:

http
Content-Type: application/json
x-payment: <x402-payment-payload>

Request Body

FieldTypeRequiredDefaultDescription
messagesarrayYes-UIMessage array containing role and content.
modelstringNoanthropic/claude-opus-4.5Target model name.
streambooleanNotrueWhether to return a streaming response.
temperaturenumberNo1Sampling temperature.
topPnumberNo1Top-p sampling parameter.
topKnumberNo40Top-k sampling parameter.

Response Modes

stream = true (default)

Returns UIMessageStream SSE (text/event-stream) using AI SDK style UIMessageChunk events. Common event types include:

  • start
  • text-start
  • text-delta
  • text-end
  • finish

The final finish event includes messageMetadata such as:

  • totalTokens
  • allowanceLeft
  • calculatedPriceWei
  • realPriceWei

stream = false

Returns a single JSON response in DGrid's standard completion format with choices and usage.

Errors

StatusMeaning
402Payment validation failed, usually because the first request omitted x-payment or the payment signature was invalid
400Invalid request or upstream validation error
500Server-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.