@neuracomputes/agent
v0.1.2
Published
Agent SDK for NEURA Compute — OpenAI-compatible inference with automatic HTTP 402 -> burn $NEURA -> retry handling, and wallet-only (SIWE) onboarding for autonomous agents.
Maintainers
Readme
@neuracomputes/agent — the agent-native SDK for NEURA Compute
OpenAI-compatible inference with the two things agents actually need:
- Automatic HTTP 402 handling — when NEURA says payment required, the SDK reads the machine-readable remediation, burns $NEURA on Base, waits for the credit, and retries. No human, no card.
- Wallet-only onboarding (SIWE / EIP-4361) — an agent holding only a wallet key creates its account and self-provisions an API key.
Use with the official OpenAI SDK (drop-in fetch)
import OpenAI from "openai";
import { NeuraAgent } from "@neuracomputes/agent";
const neura = new NeuraAgent({
apiKey: process.env.NEURA_API_KEY,
walletKey: process.env.AGENT_WALLET_KEY, // optional — enables self-funding
autoFund: true, // burn->credit->retry on 402
maxNeuraPerBurn: 100, // hard safety cap per burn
});
const openai = new OpenAI({
baseURL: "https://app.neuracomputes.com/v1",
apiKey: process.env.NEURA_API_KEY,
fetch: neura.fetch, // 402s handled transparently
});
const r = await openai.chat.completions.create({
model: "deepseek-ai/DeepSeek-V4-Pro",
messages: [{ role: "user", content: "Hello!" }],
});Zero-to-inference with only a wallet
const agent = new NeuraAgent({ walletKey: process.env.AGENT_WALLET_KEY, autoFund: true });
await agent.loginWithWallet(); // SIWE -> tenant + API key (no email, no form)
const reply = await agent.chat({ // 402 -> burnWithReason -> credited -> retry
model: "deepseek-ai/DeepSeek-V4-Pro",
messages: [{ role: "user", content: "You are funded by your own burn." }],
});Safety model (burns are permanent)
- Nothing on-chain happens unless you pass
walletKeyandautoFund: true(or callfund()yourself). - Every burn is sized from the live advertised rate; if no rate is advertised the SDK throws instead of guessing.
maxNeuraPerBurn(default 100) hard-caps any single burn.- On 402 without auto-funding,
PaymentRequiredErrorcarries the fullremediationblock and the x402 envelope so your own logic can decide. - Use a dedicated hot wallet with a small balance — never a treasury key.
API
| Member | Purpose |
|---|---|
| new NeuraAgent(opts) | apiKey, baseUrl, walletKey, autoFund, maxNeuraPerBurn, creditsPerFund, burnConfirmations, rpcUrl |
| agent.fetch | 402-aware fetch — pass to the OpenAI SDK |
| agent.chat(params) | Plain chat completion with the same 402 handling |
| agent.loginWithWallet() | SIWE login → { tenantId, address, apiKey } |
| agent.fund(remediation, credits?) | Execute a burn + submit for crediting |
| agent.creditBalance() | Current credits (1 = $1) |
| agent.discovery() | /.well-known/neura.json |
| PaymentRequiredError | Thrown on unhandled 402 — carries remediation + x402 |
Develop / publish
cd packages/neura-agent
npm install
npm test # vitest unit tests (no network, no chain)
npm run build
npm publish --access public # needs the @neura npm org