Skip to main content
POST
/
v1
/
inference
/
chat
curl -X POST https://api.mrdn.finance/v1/inference/chat \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{ "role": "user", "content": "hey" }],
    "model": "dolphinserver:24B",
    "template": "logical"
  }'
import { privateKeyToAccount } from "viem/accounts";
import { wrapFetchWithPayment } from "@meridian/x402-fetch";

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const fetchWithPayment = wrapFetchWithPayment(fetch, account);

const response = await fetchWithPayment("https://api.mrdn.finance/v1/inference/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    messages: [{ role: "user", content: "hey" }],
    model: "dolphinserver:24B",
    template: "logical",
  }),
});

for await (const chunk of response.body) {
  process.stdout.write(new TextDecoder().decode(chunk));
}
{
  "x402Version": 1,
  "error": {},
  "accepts": [
    {
      "scheme": "exact",
      "network": "base",
      "maxAmountRequired": "10000",
      "resource": "https://api.mrdn.finance/v1/inference/chat",
      "description": "One chat completion from Dolphin AI",
      "mimeType": "text/event-stream",
      "payTo": "0x8E7769D440b3460b92159Dd9C6D17302b036e2d6",
      "maxTimeoutSeconds": 60,
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "extra": { "name": "USD Coin", "version": "2" }
    }
  ]
}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"24B","choices":[{"index":0,"delta":{"role":"assistant","content":"Hey"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"24B","choices":[{"index":0,"delta":{"content":" there!"},"finish_reason":null}]}

data: [DONE]
{
  "error": "Unknown model \"gpt-4\"",
  "supported": ["dolphinserver:24B", "dolphinserver2:6b"]
}
Runs one chat completion against the selected Dolphin model. This endpoint is x402-protected: unpaid requests receive 402 Payment Required, and paid requests must include the X-PAYMENT header.

Headers

Content-Type
string
required
Must be application/json.
X-PAYMENT
string
Base64-encoded signed x402 payment payload. Omit on the first request to receive the payment requirements via a 402 response.

Body

messages
array
required
Conversation history as an array of { role, content } objects. Roles are user and assistant. Must be non-empty.
model
string
default:"dolphinserver:24B"
Model ID. Must be one of the IDs returned by GET /v1/inference/models. Invalid values return 400 with the supported list.
template
string
default:"logical"
Prompt template. Must be one of the names returned by GET /v1/inference/templates. Invalid values return 400 with the supported list.

Response

On success (200), the completion is streamed as text/event-stream. Each event is an OpenAI-style chunk; concatenate choices[0].delta.content across chunks to build the full reply. Settlement details (including the transaction hash) are returned in the X-PAYMENT-RESPONSE header.
curl -X POST https://api.mrdn.finance/v1/inference/chat \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [{ "role": "user", "content": "hey" }],
    "model": "dolphinserver:24B",
    "template": "logical"
  }'
import { privateKeyToAccount } from "viem/accounts";
import { wrapFetchWithPayment } from "@meridian/x402-fetch";

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const fetchWithPayment = wrapFetchWithPayment(fetch, account);

const response = await fetchWithPayment("https://api.mrdn.finance/v1/inference/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    messages: [{ role: "user", content: "hey" }],
    model: "dolphinserver:24B",
    template: "logical",
  }),
});

for await (const chunk of response.body) {
  process.stdout.write(new TextDecoder().decode(chunk));
}
{
  "x402Version": 1,
  "error": {},
  "accepts": [
    {
      "scheme": "exact",
      "network": "base",
      "maxAmountRequired": "10000",
      "resource": "https://api.mrdn.finance/v1/inference/chat",
      "description": "One chat completion from Dolphin AI",
      "mimeType": "text/event-stream",
      "payTo": "0x8E7769D440b3460b92159Dd9C6D17302b036e2d6",
      "maxTimeoutSeconds": 60,
      "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
      "extra": { "name": "USD Coin", "version": "2" }
    }
  ]
}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"24B","choices":[{"index":0,"delta":{"role":"assistant","content":"Hey"},"finish_reason":null}]}

data: {"id":"chatcmpl-...","object":"chat.completion.chunk","model":"24B","choices":[{"index":0,"delta":{"content":" there!"},"finish_reason":null}]}

data: [DONE]
{
  "error": "Unknown model \"gpt-4\"",
  "supported": ["dolphinserver:24B", "dolphinserver2:6b"]
}