Skip to content
GORNGORN

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).

SurfaceStatusWhat it does
GET /api/v1/modelsBuiltCatalog with per-model availability on this server: live, simulated or pending.
POST /api/inferenceBuiltMetered completion through the provider adapter (real or simulated); prices usage in credits.
GET /api/v1/credits/balanceBuiltCredit balances for the account behind the key (Demo account until the ledger is deployed).
POST /api/keysBuiltCreates an API key; returns it once, stores its SHA-256 hash.
GET /api/statusBuiltLive Elysium read: chain id, latest block, gas price.
POST /api/v1/agents/*PlannedCreate agents, set budgets, pause / resume / revoke through the treasury contract.
GET /api/v1/usagePlannedUsage per key, model and agent over a date range.
Demo honesty: without a deployed credit ledger, every key reads the seeded Demo account. The response carries source: "demo" so a client can tell.

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.

TypeScript · authenticated request
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.

Response · GET /api/v1/credits/balance
{
  "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.

TypeScript · completion
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')
FieldTypeNotes
modelIdstringAn id from GET /api/v1/models. Pending-integration models answer 409.
promptstring1 to 8,000 characters.
maxTokensnumber16 to 2,048; default 512.
The browser app books the returned credits in its Demo ledger. A server integration should do the same against its own account record; the live ledger contract will make this atomic.

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.

TypeScript · the authorization rule (built)
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)
}
Planned · REST shape
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/activity

06 · 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.

TypeScript · client shape
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.

TypeScript · fall back when the answer is simulated
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 }
}
TypeScript · read Elysium status before a write
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`)
TypeScript · read a deployed vault with viem (once an address exists)
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 · pathAuthStatus codes
GET /api/v1/modelsnone200
POST /api/inferencekey (planned: required)200 · 400 invalid body · 404 unknown model · 409 pending integration · 429 rate limit · 502 provider error
GET /api/v1/credits/balanceBearer key200 · 401
GET /api/keyssession cookie200: this browser’s prefixes and labels only
POST /api/keysnone; sets the cookie201 with the key once · 409 five active keys · 429
DELETE /api/keys?id=session cookie200 { revoked }: false unless this browser owns the key
GET /api/statusnone200 · 503 RPC unreachable
Demo scope: anyone can create a key for their own browser, and a key only reads the sample Demo account. A production deployment puts key management behind real accounts.

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.