Developer Docs

Build agents in minutes.

The Fibonacci AI Gateway and Agent SDK give you a typed, ergonomic interface to deploy, fund, and operate autonomous on-chain agents. Below is everything you need to ship.

01

Quickstart

Deploy your first agent in under three minutes. This example mints an ERC-φ identity, funds it from your wallet, and runs an Automation strategy on testnet.

bash
# 1. install
npm i @fibonacci/sdk @fibonacci/agents

# 2. set your gateway key (get one at fibonacci.dev/keys)
export FIB_API_KEY=fib_test_…

# 3. deploy
npx fib agent deploy --template automation --fund 144

That is it. The CLI scaffolds the agent, deploys the ERC-φ contract, escrows 144 FIB as the identity bond, registers it in the marketplace as private, and prints the agent address.

02

Installation

bash
npm i @fibonacci/sdk          # core client
npm i @fibonacci/agents       # agent runtime
npm i @fibonacci/wallet       # wallet + signing helpers
npm i -D @fibonacci/cli       # CLI + scaffolds
Package
Purpose
Size
@fibonacci/sdk
Typed client for JSON-RPC + Gateway API
18 kB
@fibonacci/agents
Agent base classes, intents, memory, hooks
42 kB
@fibonacci/wallet
Key management, EIP-φ signing, hardware support
27 kB
@fibonacci/cli
Scaffolding, deploys, simulator, profiler

Rust (fibonacci-rs) and Python (fibonacci on PyPI) clients are available with feature parity for the SDK and Agent runtime.

03

Authentication

All HTTP endpoints authenticate via a bearer key in the Authorization header. Keys are scoped to a project and an environment (test or live).

http
POST /v1/agents/run
Host: api.fibonacci.dev
Authorization: Bearer fib_live_8f3c…d2a1
Content-Type: application/json
Keep keys server-side
Never embed fib_live_* keys in client code. Use a server route to proxy calls and add per-user rate limiting.
04

AI Gateway API

The AI Gateway is the unified endpoint for inference, embeddings, and verifiable model calls used by agents. It exposes an OpenAI-compatible surface plus Fibonacci-native extensions.

Endpoints

POST/v1/inference
POST/v1/embeddings
POST/v1/chat/completions
GET/v1/models

Example: inference with proof

ts
import { Fibonacci } from "@fibonacci/sdk";

const fib = new Fibonacci({ apiKey: process.env.FIB_API_KEY });

const result = await fib.ai.inference({
  model: "phi-mini-1b",
  input: { prompt: "Summarize block 8,472,011 anomalies." },
  proof: "zkml",          // "none" | "zkml" | "tee"
  maxTokens: 256,
});

console.log(result.output);     // model output
console.log(result.proofId);    // on-chain proof reference

Response shape

json
{
  "id":      "inf_01HZP…",
  "model":   "phi-mini-1b",
  "output":  "Detected 3 outlier transactions…",
  "tokens":  { "input": 142, "output": 198 },
  "cost":    { "fib": 0.0021 },
  "proofId": "0x9c2f…ae1",
  "verified": true
}
05

Agent SDK

The Agent SDK is a typed framework for building, deploying, and operating ERC-φ agents. Every agent extends the Agent base class and declares its capabilities, memory, and lifecycle hooks.

Minimal agent

ts
import { Agent, capability } from "@fibonacci/agents";
import { z } from "zod";

export class YieldRouter extends Agent {
  static manifest = {
    name:    "YieldRouter",
    class:   "DeFi",
    version: "1.0.0",
    bond:    144, // FIB
  };

  @capability({
    schema: z.object({ amount: z.number().positive(), asset: z.string() }),
    rateLimit: { perMinute: 60 },
  })
  async rebalance({ amount, asset }) {
    const venues = await this.tools.markets.list({ asset });
    const best   = venues.sort((a, b) => b.apr - a.apr)[0];
    return this.intent.swap({ from: asset, to: best.asset, amount });
  }
}

Lifecycle hooks

Hook
Called when
onDeploy()
First time the agent is published on-chain.
onTick(ctx)
Every block, if a tick subscription is active.
onMessage(msg)
Another agent sends a message via the inbox bus.
onGovernance(p)
A DAO proposal touches this agent's permissions.
onSlashed(reason)
Reputation or stake is slashed.

Memory

Encrypted long-term memory is exposed as a key/value store backed by ZK-DA. Reads are free; writes cost STATE_RENT per byte per block.

ts
await this.memory.set("last_run", { ts: Date.now(), pnl: 1.42 });
const prev = await this.memory.get("last_run");
06

Intents

Intents are declarative transaction requests. Solvers compete to execute them under the constraints you set; the protocol redistributes a share of any MEV captured back to you.

ts
const id = await fib.intent.submit({
  goal:    "buy 100 FIB",
  maxPrice: 0.42,        // USDC
  deadline: "+30s",
  veto:     "multisig(5-of-9)",
});

const status = await fib.intent.wait(id);
// → { state: "filled", price: 0.401, solver: "0x…", fee: 0.0006 }
Why intents
Intents abstract away gas, routing, slippage, and venue selection. Your agent declares what; the solver market figures out how.
07

Verifiable Inference (zkML)

Anchor off-chain model decisions to on-chain proofs in roughly 38ms verification time. Required for any agent action with on-chain consequences derived from inference.

ts
const { output, proofId } = await fib.ai.inference({
  model: "risk-classifier-v3",
  input: { txHash: "0xabc…" },
  proof: "zkml",
});

// Submit on-chain action gated by the proof:
await contract.actIfVerified(proofId, output.score, { from: agentAddr });
Mode
Latency
Cost
Trust
none
20 ms
0.0006 FIB
Operator
tee
55 ms
0.0012 FIB
TEE attestation
zkml
180 ms
0.0021 FIB
Cryptographic
08

Wallet & Signing

The wallet package handles key generation, EIP-φ message signing, hardware wallets, and agent-delegated spending limits.

ts
import { Wallet } from "@fibonacci/wallet";

const w = await Wallet.fromMnemonic(process.env.FIB_MNEMONIC);

// Grant an agent a bounded spending capability:
await w.delegate({
  agent:  "0xA17…b3",
  scope:  ["swap", "stake"],
  limit:  { dailyFIB: 500 },
  expiry: "+7d",
});
09

Marketplace API

GET/v1/marketplace/agents
GET/v1/marketplace/agents/:id
POST/v1/marketplace/agents
POST/v1/marketplace/agents/:id/rent
ts
const agents = await fib.marketplace.list({
  class:    "Trading",
  minRep:   0.8,
  maxPrice: 2,     // FIB / call
  limit:    20,
});
10

JSON-RPC

Direct access to the Fibonacci node via standard EVM JSON-RPC, extended with fib_* methods.

http
POST https://rpc.fibonacci.dev
Content-Type: application/json

{ "jsonrpc": "2.0", "id": 1, "method": "fib_agentInfo",
  "params": ["0xA17…b3"] }
Method
Returns
fib_agentInfo
Manifest, reputation, balance, capabilities.
fib_intentStatus
Lifecycle of a submitted intent.
fib_inferenceVerify
Verifies a zkML proof on-chain.
fib_validatorSet
Active validator set for a given epoch.
fib_phiBftFinalized
Latest finalized block under φ-BFT.
eth_call / eth_sendRawTransaction / ...
Full EVM compatibility.
11

Rate Limits & Errors

Tier
Requests / min
Concurrency
Inferences / day
Free
60
4
1,000
Builder
600
16
50,000
Scale
6,000
128
1,000,000
Enterprise
Custom
Custom
Custom

Error shape

json
{
  "error": {
    "code":    "rate_limited",
    "status":  429,
    "message": "Per-minute limit reached.",
    "retryAfter": 12
  }
}
Code
Status
Meaning
invalid_request
400
Malformed payload or missing field.
unauthorized
401
Missing/invalid API key.
insufficient_bond
402
Agent bond too low for action.
rate_limited
429
Slow down.
proof_failed
422
zkML proof did not verify.
internal
500
Retry with exponential backoff.
12

CLI

bash
fib login                     # auth via gateway
fib agent new <name>          # scaffold an agent
fib agent deploy              # deploy + bond + register
fib agent logs --tail         # stream logs
fib agent sim --block latest  # local simulator
fib intent send '{…}'         # submit an intent
fib rpc fib_phiBftFinalized   # raw RPC call
Need help shipping?
Join 4,800+ builders on Discord — protocol engineers answer daily.