Developer portal
Build on the GORN intelligence economy.
Credit balance, AI inference and agent treasury APIs with TypeScript examples. What is built is marked built; what is planned is marked planned.
01 · API overview
Build on the GORN intelligence economy.
GORN exposes the credit balance, the inference marketplace and the agent treasury through one HTTP API under /api/v1, authenticated with API keys. Credits are the unit of account: a credit is prepaid AI capacity created from realized vault yield (1 credit = 1 USD in Demo mode).
| Surface | Status | What it does |
|---|---|---|
| GET /api/v1/models | Built | Catalog with per-model availability on this server: live, simulated or pending. |
| POST /api/inference | Built | Metered completion through the provider adapter (real or simulated); prices usage in credits. |
| GET /api/v1/credits/balance | Built | Credit balances for the account behind the key (Demo account until the ledger is deployed). |
| POST /api/keys | Built | Creates an API key; returns it once, stores its SHA-256 hash. |
| GET /api/status | Built | Live Elysium read: chain id, latest block, gas price. |
| POST /api/v1/agents/* | Planned | Create agents, set budgets, pause / resume / revoke through the treasury contract. |
| GET /api/v1/usage | Planned | Usage per key, model and agent over a date range. |
02 · Authentication
API keys, shown once and stored hashed.
Create a key in the application (Settings → API keys) or with POST /api/keys. The key is returned exactly once; the server keeps only its SHA-256 hash and the prefix for display. Send it as a Bearer token. Keys never belong in client-side code: call GORN from your server.
const GORN_API_KEY = process.env.GORN_API_KEY! // server-side only, never NEXT_PUBLIC_
const res = await fetch('https://your-gorn-host/api/v1/credits/balance', {
headers: { Authorization: `Bearer ${GORN_API_KEY}` },
})
if (res.status === 401) throw new Error('invalid or revoked key')
const { balances, source } = await res.json()
console.log(balances.available, source) // e.g. 148.32 "demo"- Revoke a key with DELETE /api/keys?id=<id>; revoked keys answer 401 immediately.
- Rate limits: 30 inference requests and 10 key creations per minute per client address.
- Keys belong to the browser session that created them (an httpOnly cookie): nobody else can list or revoke them. At most 5 active keys per browser.
- The demo key store is the memory of one server instance, so a key can stop working at any time and is then refused. A production deployment keeps the same hashes in a database.
03 · Credit balance API
Read what an account can spend.
Balances are derived from the ledger, never stored: available = generated − consumed − reserved. A credit exists only because a recorded funding event (a yield conversion) created it.
{
"account": { "keyId": "3f9a1c2b7d0e", "label": "staging backend" },
"source": "demo",
"balances": { "generated": 312.4, "consumed": 164.08, "reserved": 0, "available": 148.32 },
"unit": "credit",
"note": "Demo account balance. Live balances follow the credit ledger deployment."
}04 · AI inference API
One request, any model, metered in credits.
POST /api/inference routes the prompt to the model’s provider adapter. When the provider is configured on the server the response is live; otherwise it is simulated and says so (source: "simulated", with a banner in the text). Usage is metered and priced at the model’s per-million-token rates.
type InferenceResult = {
text: string
usage: { inputTokens: number; outputTokens: number }
credits: number // charged to the caller's ledger
source: 'live' | 'simulated'
provider: string; model: string; latencyMs: number
}
const res = await fetch('https://your-gorn-host/api/inference', {
method: 'POST',
headers: { 'content-type': 'application/json', Authorization: `Bearer ${process.env.GORN_API_KEY}` },
body: JSON.stringify({ modelId: 'claude-sonnet-5-5', prompt: 'Summarize this vault strategy…', maxTokens: 400 }),
})
const result: InferenceResult = await res.json()
if (result.source === 'simulated') console.warn('no provider configured on this server')| Field | Type | Notes |
|---|---|---|
| modelId | string | An id from GET /api/v1/models. Pending-integration models answer 409. |
| prompt | string | 1 to 8,000 characters. |
| maxTokens | number | 16 to 2,048; default 512. |
05 · Agent treasury API
Programmable, bounded, reversible funding for agents.
Every agent has a budget, a daily limit, a per-transaction maximum, a set of allowed services and a status. One authorization rule decides every spend; it lives in lib/agents/budget.ts and, for the on-chain version, in contracts/src/GornAgentTreasury.sol. The HTTP surface is planned; the rule is already enforced in the application.
import { authorizeSpend } from '@/lib/agents/budget'
const decision = authorizeSpend(agent, 2.5, 'research', Date.now(), accountAvailable)
if (!decision.ok) {
// 'Agent is paused.' | 'Above the maximum transaction amount…' | 'Would exceed the daily spending limit…' | …
log.deny(agent.id, decision.reason)
}POST /api/v1/agents { name, wallet, budget, dailyLimit, maxTransaction, allowedServices }
POST /api/v1/agents/:id/pause | resume | revoke
POST /api/v1/agents/:id/spend { amount, service } -> 200 authorized | 403 { reason }
GET /api/v1/agents/:id/activity06 · Usage tracking
Every call is a ledger entry.
Consumption is recorded per call with the model, token counts, credits and source. In the application this is the AI Credits ledger and the Activity page (CSV export). The usage endpoint that aggregates it per key, model and agent over a date range is planned.
- Per-operation and daily spending limits apply to the whole account (AI Credits → conversion settings).
- Agent spends are attributed to the agent and count against both the agent limits and the account limits.
- Simulated and live calls are stored with their source so reports can separate them.
07 · SDK
A thin TypeScript client.
The SDK is a small wrapper over the HTTP API. It is not published to npm yet; the shape below is the contract the published package will keep.
import { GornClient } from '@gorn/sdk' // planned package
const gorn = new GornClient({ apiKey: process.env.GORN_API_KEY!, baseUrl: 'https://your-gorn-host' })
const balance = await gorn.credits.balance()
const models = await gorn.models.list()
const answer = await gorn.inference.complete({ modelId: 'gorn-sim-lm-1', prompt: 'Hello', maxTokens: 200 })
// agents (planned endpoints)
const agent = await gorn.agents.create({ name: 'Research Scout', wallet: '0x…', budget: 120, dailyLimit: 15, maxTransaction: 4, allowedServices: ['research'] })
await gorn.agents.pause(agent.id)08 · Code examples
Common integrations.
async function ask(prompt: string) {
const res = await fetch(`${BASE}/api/inference`, { method: 'POST', headers, body: JSON.stringify({ modelId: 'claude-haiku-5-5', prompt }) })
if (res.status === 409) return { text: 'model pending integration', simulated: true }
const r = await res.json()
return { text: r.text, simulated: r.source === 'simulated', credits: r.credits }
}const status = await fetch(`${BASE}/api/status`).then((r) => r.json())
if (!status.ok || status.chainId !== 99901) throw new Error('Elysium RPC unavailable or wrong chain')
console.log(`block ${status.block}, gas ${status.gasGwei} gwei`)import { createPublicClient, http } from 'viem'
import { elysium } from '@/config/network'
import { gornVaultAbi } from '@/lib/contracts/abi'
const client = createPublicClient({ chain: elysium, transport: http() })
const totalAssets = await client.readContract({ address: VAULT, abi: gornVaultAbi, functionName: 'totalAssets' })09 · API reference
Endpoints and errors.
| Method · path | Auth | Status codes |
|---|---|---|
| GET /api/v1/models | none | 200 |
| POST /api/inference | key (planned: required) | 200 · 400 invalid body · 404 unknown model · 409 pending integration · 429 rate limit · 502 provider error |
| GET /api/v1/credits/balance | Bearer key | 200 · 401 |
| GET /api/keys | session cookie | 200: this browser’s prefixes and labels only |
| POST /api/keys | none; sets the cookie | 201 with the key once · 409 five active keys · 429 |
| DELETE /api/keys?id= | session cookie | 200 { revoked }: false unless this browser owns the key |
| GET /api/status | none | 200 · 503 RPC unreachable |
10 · Integration guide
From zero to a funded agent.
- 1. Create an API key in Settings and store it in your server environment.
- 2. Read GET /api/v1/models and pick a model whose availability is live or simulated.
- 3. Call POST /api/inference from your server; record the returned credits against your account.
- 4. Create an agent in the Agent Treasury with a budget and limits; have your agent process call the (planned) spend endpoint or run the authorization rule from lib/agents/budget.ts.
- 5. Watch the Activity page or export CSV to reconcile usage.
- 6. When the contracts are deployed, set the NEXT_PUBLIC_GORN_* addresses: the same interfaces switch from Demo to live.
Network: Elysium (Kinetiq), chain id 99901, gas in HYPE, public RPC https://rpc.elysium.kinetiq.xyz, explorer https://elysium.kinetiq.xyz. The centralized configuration is src/config/network.ts and pnpm verify:network checks it against the live chain.