Embeddings (OpenAI-compatible)
POST /v1/embeddingsOpenAI-compatible text embeddings over x402 - point any OpenAI SDK at base_url https://agent402.tools/v1 and pay $0.002 per call in USDC, no API key, no signup. Send POST /v1/embeddings with the required field input and pay $0.002 per call over x402 or MPP (there is no free tier). It returns a JSON object with object, data, model and usage.
Batch up to 64 inputs / 16k chars per request; text-embedding-3-small by default (3-large and ada-002 supported; dimensions and encoding_format pass through). Embeddings are deterministic, so a byte-identical repeat within 10 minutes is served FREE from cache automatically (X-Cache: hit; opt out with cache:false).
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
input | string | yes | Text to embed - a string or an array of up to 64 strings (16k chars total) Also accepted as text, data, str, string, body, content. |
model | string | no | Optional - text-embedding-3-small (default), text-embedding-3-large, or text-embedding-ada-002 |
dimensions | number | no | Optional output dimensions (3-small/3-large only) |
Example request
curl -i -X POST https://agent402.tools/v1/embeddings \
-H "Content-Type: application/json" \
-d '{"input":"Agent402 is an open-source x402 tool server."}'
Without payment this returns HTTP 402 Payment Required with the exact price for v1-embeddings; any x402 v2 or MPP client pays it and retries.
Example response
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
0.0023,
-0.0091,
0.0152
]
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 12,
"total_tokens": 12
}
}
| Field | Type | Always present | In the example |
|---|---|---|---|
object | string | yes | list |
data | array of objects | yes | 1 item in the example |
model | string | yes | text-embedding-3-small |
usage | object | yes | 2 fields: prompt_tokens, total_tokens |
From an MCP client
catalog.call {
"slug": "v1-embeddings",
"params": {
"input": "Agent402 is an open-source x402 tool server."
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for v1-embeddings; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.
Errors and behavior
inputis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement is cancelled when the tool fails. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool runs a model, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Model-backed: the answer is generated by a model, so the same input can produce different wording.
- A
GETorHEADto /v1/embeddings returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB and a streamed response are not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/v1/embeddings", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"input": "Agent402 is an open-source x402 tool server."
}),
});
Related tools
Rerank (Cohere-compatible)
POST /v1/rerankRerank documents against a query over x402 - the Cohere /rerank wire ({query, documents[], top_n} -> results with releva…
Text-to-speech (OpenAI-compatible)
POST /v1/audio/speechOpenAI-compatible text-to-speech over x402 - point any OpenAI SDK's audio.speech.create() at base_url https://agent402.t…
Chat completions (OpenAI-compatible)
POST /v1/chat/completionsOpenAI-compatible chat completions, base tier: point any OpenAI SDK at base_url https://agent402.tools/v1 and pay per ca…
Chat completions - auto tier (eval-ranked routing)
POST /v1/auto/chat/completionsOpenAI-compatible chat completions with server-side model choice: omit "model" (or send "auto") and the gateway routes t…
Grounded chat (web search, OpenAI-compatible)
POST /v1/grounded/chat/completionsOpenAI-compatible chat completions GROUNDED in a live web search on every call: the gateway runs an Exa search (up to 5 …
Chat completions - metered (pay what the call costs)
POST /v1/metered/chat/completionsOpenAI-compatible chat completions billed per request from what the call costs: the 402 quotes exact-BPE input plus your…