PHΛSE Docs PHASE.XYZ

Call a model

The examples call a paid model through the Phase SDKs.

GET /v1/models returns the catalog with prices and needs no payment; use it to choose a model and a max_amount.

# A paid model answers 402 with the quote (ceiling, price per 1M, task id);
# sign it with an SDK below — or look at the quote first:
curl -s -i -X POST https://<gateway>/v1/chat/completions -H 'content-type: application/json' \
  -d '{"model":"gpt-oss-120b","messages":[{"role":"user","content":"hello world"}]}'

# The catalog with prices (no payment):
curl -s https://<gateway>/v1/models

#OpenAI Node SDK

TypeScript
import OpenAI from "openai";
import { createPayingFetch } from "@phase/x402-fetch";
import { privateKeyToAccount } from "viem/accounts";

const payingFetch = createPayingFetch({ signer: privateKeyToAccount(process.env.PHASE_WALLET_KEY) });
const openai = new OpenAI({ baseURL: "https://<gateway>/v1", apiKey: "x402", fetch: payingFetch });

const stream = await openai.chat.completions.create({ model: "gpt-oss-120b", stream: true, messages: [{ role: "user", content: "hi" }] });
for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
  if (chunk.phase) console.log("\npaid", chunk.phase.price_micro_usd, "µUSD", chunk.phase.payment, chunk.phase.tx_hash);
}

#Model classes

Instead of a model id you can name a class: auto (balanced, default), eco (cheapest), premium (best quality) or agentic (multi-step tool use). The router picks a model of that class for each message and buys it from the cheapest healthy provider; you pay the routed model's own price plus the per-call fee.

Terminal
curl -s -i -X POST https://<gateway>/v1/chat/completions -H 'content-type: application/json' \
  -d '{"model":"auto","messages":[{"role":"user","content":"hello world"}]}'

Free models need no payment, but a gateway may disable them.

#This gateway

The network, the recipient (InferencePayments) and the asset (USDT) are in every 402 response (accepts[0]); the gateway signer is in GET /health.

Pin the recipient, the asset and the network in your SDK (allowed_pay_to / allowedPayTo, allowed_assets / allowedAssets, networks) using values from an independent source, not values read from the same gateway URL: then a wrong or hijacked gateway URL cannot make your wallet sign for another recipient. The SDKs also refuse to pay a plain-http gateway unless it is loopback (dev) or you opt in with allow_insecure.

#SDK options

All options and more examples: SDKs.

© 2026 Phase Labs Technologies Inc. All rights reserved. Phase is a product of Phase Labs Technologies Inc.ir-quickstart.md