bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 10쪽 중 10쪽
monopolies.
* Via a distributed node network and elastic scheduling mechanism, we address the high costs, single points of failure, and censorship risks of centralized AI, while providing a merit-based incentive system for node operators.
Ultimately, DGrid aims to become the **"value hub"** of the AI and Web3 ecosystems. We not only deliver cost-effective, verifiable, high-quality AI services to users but also build a fair and win-win collaboration platform for ecosystem participants, advancing AI from **"centralized services"** to a **"foundational public utility of the open web"**.
## Core Values
* **Decentralization**: AI belongs to the open web, not centralized platforms, ensuring equal participation of all ecosystem stakeholders.
* **Accessibility**: Anyone can join as a node operator, developer, creator, or user, with low barriers to entry.
* **Trustlessness**: Based on on-chain permission and auditing mechanisms, services are verifiable and traceable without relying on third-party trust.
* **Scalability**: Modular design enables flexible model deployment, inference, and caching, adapting to diverse scenario requirements.
* **Value Discoverability**: Intelligent routing makes inference resources "routable, verifiable, and comparable in price", enabling efficient allocation of intelligent liquidity.
# API Reference
Source: https://docs.dgrid.ai/x402/api-reference
Endpoint reference for DGrid's x402 API, including request format, payment headers, response codes, and pay-per-inference billing details.
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](/api-reference/introduction). 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.
```http theme={null}
POST /x402/v1
```
| | |
| ----------------- | ------------------------------------------------------------------- |
| **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:
```http theme={null}
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:
* `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
| 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.
<RequestExample>
```bash Step 1: Trigger 402 theme={null}
curl -i 'https://api.dgrid.ai/x402/v1/responses' \
-H 'Content-Type: application/json' \
--data-raw '{
"model": "anthropic/claude-opus-4.5",
"stream": true,
"messages": [
{ "role": "user", "content": "Hello" }
]
}'
```
```bash Step 2: Retry with x-payment theme={null}
curl -i 'https://api.dgrid.ai/x402/v1' \
-H 'Content-Type: application/json' \
-H 'x-payment: <x402-payment-payload>' \
--data-raw '{
"model": "anthropic/claude-opus-4.5",
"stream": true,
"messages": [
{ "role": "user", "content": "Hello" }
]
}'
```
</RequestExample>
<ResponseExample>
```http 402 Response theme={null}
HTTP/1.1 402 Payment Required
Content-Type: application/json
X-PAYMENT-RESPONSE: <base64>
{
"x402Version": 1,
"error": "Payment required",
"accepts": [
{
"scheme": "upto",
"network": "eip155:56",
"maxAmountRequired": "990000000000000000",
"resource": "https://api.dgrid.ai/x402/v1",
"payTo": "0x...",
"asset": "0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d",
"maxTimeoutSeconds": 86400
}
]
}
```
```text Streaming Response theme={null}
data: {"type":"start"}
data: {"type":"text-start","id":"..."}
data: {"type":"text-delta","id":"...","delta":"Hello"}
data: {"type":"text-end","id":"..."}
data: {"type":"finish","finishReason":"stop","messageMetadata":{"totalTokens":123,"allowanceLeft":"990000000000000000","calculatedPriceWei":"1230000000000000","realPriceWei":"1230000000000000"}}
```
```json Non-Streaming Response theme={null}
{
"id": "chatcmpl-xxxx",
"object": "chat.completion",
"created": 1773823863,
"model": "grok-4-fast",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "xxxxx"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 11,
"completion_tokens": 323,
"total_tokens": 334
}
}
```
</ResponseExample>
# x402 API
Source: https://docs.dgrid.ai/x402/overview
DGrid's x402 API lets developers pay per inference call using the x402 micropayment protocol — no API keys or accounts required.
**DGrid x402 API** is DGrid's pay-per-inference access mode for api payments. Instead of creating an account, pre-funding a balance, or managing separate billing flows, developers and autonomous agents can pay LLM inference costs directly through the **x402 payment protocol** as part of the API request lifecycle.
This makes x402 especially useful for:
* **Agents and autonomous workflows** that need to call an LLM and settle payment immediately
* **Server-side tools and scripts** that should avoid account provisioning and manual top-ups
* **On-demand integrations** where the simplest path is "request inference, authorize payment, receive the result"
## Why x402 API Matters
Traditional AI billing usually requires:
* Creating an account with the provider
* Funding a prepaid balance or attaching a billing method
* Managing API keys, quotas, and billing dashboards
With x402 on DGrid, the flow becomes much more direct:
<Tip>
Request inference → receive payment requirements → sign once → submit payment and inference together
</Tip>
For agentic systems, this is a major simplification. The same runtime that decides to use a model can also authorize and settle the cost of that inference call, without switching into a separate account-management workflow.
## Primary Use Case: Agents Paying for Inference
x402 is designed for the case where an **agent** needs to:
1. Choose a model
2. Call the model API
3. Pay the inference fee
4. Continue execution with the result
This is valuable for:
* AI agents operating in backend workflows
* Web3 agents or protocols that want payment-aware inference
* Multi-step automations that should treat inference as a directly payable resource
## How the Flow Works
x402 on DGrid uses a **two-step request flow**:
1. **Initial request without `x-payment`**
The server returns `402 Payment Required` plus signable payment requirements.
2. **Client signs and retries**
The client generates the `x-payment` payload and sends the same inference request again with the payment header.
This pattern keeps payment authorization explicit while still letting the inference call remain simple and automatable.
## Supported Payment Asset
The current x402 endpoint uses:
* **Protocol**: x402
* **Network**: `eip155:56` (BSC)
* **Payment token**: `USD1`
* **Asset contract**: `0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d`
## Operational Notes
After successful settlement, the service records payment logs into the `x402_payment_logs` table on the backend.
## When to Use x402 vs AI Gateway
Use **AI Gateway** when you want:
* classic API-key access
* unified account-based model routing
* long-running product integrations with standard billing workflows
Use **x402** when you want:
* direct per-request payment
* no pre-funded account balance
* agent-friendly inference plus payment in one flow프로젝트로 돌아가기