Get started
Quickstart
Three steps: create a key, add credit, call a model. No email and no password. You can also do all of this in the console.
1. Create a key
curl -X POST https://inference.dagon.so/v1/keysimport requests
r = requests.post("https://inference.dagon.so/v1/keys", json={"name": "my app"})
print(r.json()["key"]) # gk_..., shown onceconst r = await fetch("https://inference.dagon.so/v1/keys", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ name: "my app" }),
});
const { key } = await r.json(); // gk_..., shown onceThe answer is 201 with key (the secret) and data (the key's id, name and balances in micro-USD). name is optional, at most 80 characters.
Save the key now
The secret is shown once. The gateway stores only a hash, so a lost key cannot be shown again or recovered, and its balance is lost with it. Keys minted under a passkey account can be deleted and replaced.
2. Add credit
Open a hosted USDC checkout for $5 to $1,000, in whole cents:
curl https://inference.dagon.so/v1/credits/checkout \
-H "Authorization: Bearer $DAGON_KEY" \
-H "Content-Type: application/json" \
-d '{"amount_usd": 20}'import os, requests
r = requests.post(
"https://inference.dagon.so/v1/credits/checkout",
headers={"Authorization": f"Bearer {os.environ['DAGON_KEY']}"},
json={"amount_usd": 20},
)
print(r.json()["url"]) # open it and pay in USDCconst r = await fetch("https://inference.dagon.so/v1/credits/checkout", {
method: "POST",
headers: { authorization: `Bearer ${process.env.DAGON_KEY}`, "content-type": "application/json" },
body: JSON.stringify({ amount_usd: 20 }),
});
const { url } = await r.json(); // open it and pay in USDCThe answer is {"session_id", "url"}. Pay on the page at https://pay.dagon.so; the credit posts once the payment is final. An agent with a Solana wallet can instead buy credits without a browser, or skip the key and pay per request with x402.
3. Call a model
curl https://inference.dagon.so/v1/chat/completions \
-H "Authorization: Bearer $DAGON_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "abliterated-model-large-flash",
"messages": [{"role": "user", "content": "Explain this stack trace."}],
"max_tokens": 1024
}'# pip install openai
import os
from openai import OpenAI
client = OpenAI(base_url="https://inference.dagon.so/v1", api_key=os.environ["DAGON_KEY"])
reply = client.chat.completions.create(
model="abliterated-model-large-flash",
messages=[{"role": "user", "content": "Explain this stack trace."}],
max_tokens=1024,
)
print(reply.choices[0].message.content)// npm install openai
import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://inference.dagon.so/v1", apiKey: process.env.DAGON_KEY });
const reply = await client.chat.completions.create({
model: "abliterated-model-large-flash",
messages: [{ role: "user", content: "Explain this stack trace." }],
max_tokens: 1024,
});
console.log(reply.choices[0].message.content);Any listed model id works; see Models and pricing. The response is the provider's OpenAI-format answer, with x-gateway-request-id and x-gateway-receipt-id headers added.
4. Check the balance
curl https://inference.dagon.so/v1/credits -H "Authorization: Bearer $DAGON_KEY"r = requests.get("https://inference.dagon.so/v1/credits", headers={"Authorization": f"Bearer {os.environ['DAGON_KEY']}"})
print(r.json()["data"]) # total_credits, total_usage, available (USD)const r = await fetch("https://inference.dagon.so/v1/credits", { headers: { authorization: `Bearer ${process.env.DAGON_KEY}` } });
console.log((await r.json()).data); // total_credits, total_usage, available (USD)available is credit minus usage minus what in-flight requests hold. GET /v1/credits/history lists the last 50 credits (id, amount_micros, source, created_at).
Last updated