Run an agent on its own key
Create the agent's API key
An agent calls models with a Platform API key that identifies it. Create one on the agent's page under Agents (API keys for this agent, then Create key), with POST /agents/{id}/keys, or with the create_agent_key MCP tool. Your own key needs manage.
curl https://platform.tenzro.xyz/api/agents/agt_Zp3kQ9x1RmW4sT/keys \
-H "Authorization: Bearer $TENZRO_MANAGE_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "research-bot prod"}'{
"id": "key_Zb81Qm0sP4aT",
"name": "research-bot prod",
"prefix": "tzl_3kQ9aZ1x",
"permissions": ["inference"],
"agent_id": "agt_Zp3kQ9x1RmW4sT",
"created_at": "2026-09-26T08:00:00.000Z",
"last_used_at": null,
"revoked_at": null,
"secret": "tzl_…"
}{
"agent_id": "agt_Zp3kQ9x1RmW4sT",
"name": "research-bot prod"
}- The key has the
inferencepermission only. The secret is returned once; keep it where the agent runs. - Only an active agent can be given keys. For one still waiting for approval, the call is refused with
409 agent_not_active. - Usage is billed to your credit and counted against the agent's approved limits, separately from yours.
Call models with it
The agent uses the same model API and endpoints as any other caller, exactly as in tutorial 01. Only the key changes.
export TENZRO_API_KEY="tzl_..." # the agent's keyimport os
from openai import OpenAI
client = OpenAI(base_url="https://api.tenzro.xyz/v1", api_key=os.environ["TENZRO_API_KEY"])
reply = client.chat.completions.create(
model="qwen3.5-4b",
messages=[
{"role": "system", "content": "You are research-bot. Answer briefly."},
{"role": "user", "content": "Summarise what an embedding is."},
],
)
print(reply.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({ baseURL: "https://api.tenzro.xyz/v1", apiKey: process.env.TENZRO_API_KEY });
const vectors = await client.embeddings.create({
model: "qwen3-embedding-0.6b",
input: ["first passage", "second passage"],
});
console.log(vectors.data.length);Stay within the approved limits
Every limit comes from the settings the owner approved with their passkey; a proposal that is still waiting is never enforced. Within them the agent works with no further prompts. Beyond them, the request is refused before any work is done:
402 agent_daily_limitdaily_limit_credits402 agent_total_limittotal_limit_credits403 agent_expiredexpires_in_days403 agent_inactivestatus{
"error": {
"message": "This agent's key may not make requests now (agent daily limit).",
"type": "insufficient_quota",
"code": "agent_daily_limit"
}
}Payments are capped on the Tenzro Network itself by max_transaction_tnzo and max_daily_tnzo. When the network refuses something outside the agent's scope, the refusal is returned as it is, never as partial success.
Handle a refusal in the agent
from openai import APIStatusError
try:
reply = client.chat.completions.create(
model="qwen3.5-4b",
messages=[{"role": "user", "content": "Next task"}],
)
except APIStatusError as e:
if e.code in ("agent_daily_limit", "agent_total_limit", "agent_expired", "agent_inactive"):
# Stop and report: retrying will not succeed until the owner approves new limits.
print("Refused:", e.code)
else:
raiseWatch what it spends
GET /agents/{id} and the get_agent MCP tool include spend.today_credits and spend.total_credits next to its approved limits. The agent's page shows the same under Platform spend.
curl -s https://platform.tenzro.xyz/api/agents/agt_Zp3kQ9x1RmW4sT \
-H "Authorization: Bearer $TENZRO_READ_KEY" | jq '{status, limits, spend}'{
"status": "active",
"limits": {
"max_transaction_tnzo": null,
"max_daily_tnzo": null,
"daily_limit_credits": 20000,
"total_limit_credits": 500000,
"expires_in_days": 90
},
"spend": { "today_credits": 0, "total_credits": 0 }
}Raise a limit
The agent cannot raise its own limits, and neither can the Platform. Propose new settings with POST /agents/{id}/settings or update_agent; the owner approves them with their passkey on https://accounts.tenzro.xyz. Nothing changes until then, and the agent keeps working under its current limits.
curl https://platform.tenzro.xyz/api/agents/agt_Zp3kQ9x1RmW4sT/settings \
-H "Authorization: Bearer $TENZRO_MANAGE_KEY" \
-H "Content-Type: application/json" \
-d '{"daily_limit_credits": 50000}'
# returns { "approve_url": "https://accounts.tenzro.xyz/agents/approve/apr_…", "agent": { … } }Revoke a key or the agent
Revoke one key to rotate it; that takes effect at once. Revoking the agent is a proposal the owner approves with their passkey.
DELETE /keys/{id}revoke_api_key(key_id)POST /agents/{id}/revokerevoke_agent(agent_id)# One key
curl -X DELETE https://platform.tenzro.xyz/api/keys/key_Zb81Qm0sP4aT -H "Authorization: Bearer $TENZRO_MANAGE_KEY"
# The agent: returns an approve_url for the owner
curl -X POST https://platform.tenzro.xyz/api/agents/agt_Zp3kQ9x1RmW4sT/revoke -H "Authorization: Bearer $TENZRO_MANAGE_KEY"