Valta Docs
Installation
Install
bash
npm install valta-sdk
Requirements
- Node.js 18 or later
- TypeScript 5.0+ recommended
Works in Next.js, Express, Fastify, plain Node.js, and Bun.
Environment setup
Add your API key to your environment. Never commit it to git.
bash
# .env.local (gitignored)
VALTA_API_KEY=sk_valta_...
Initialize the client
ts
import { ValtaClient } from 'valta-sdk'
const valta = new ValtaClient({
apiKey: process.env.VALTA_API_KEY,
baseUrl: 'https://valta.co/api/v1', // optional — defaults to production
})
ESM and CommonJS
ts
// ESM
import { ValtaClient } from 'valta-sdk'
// CommonJS
const { ValtaClient } = require('valta-sdk')
TypeScript types
The SDK exports the following types:
| Type | Description |
|---|---|
Agent | Agent object returned by create, get, and list. |
AgentRun | Result of an agent run, including status and summary. |
Policy | Spending policy with all limit and restriction fields. |
WalletInfo | Wallet balance, currency, and status. |
AuditEntry | Single audit trail entry with hash chain fields. |
ApiKey | API key metadata (never includes the full key value). |
PaginatedResponse<T> | Generic paginated wrapper with data, total, and page. |
Error handling
All SDK methods throw ValtaError on non-2xx responses.
ts
import { ValtaClient, ValtaError } from 'valta-sdk'
const valta = new ValtaClient({ apiKey: process.env.VALTA_API_KEY })
try {
const agent = await valta.agents.get('invalid-id')
} catch (err) {
if (err instanceof ValtaError) {
console.log(err.status) // 404
console.log(err.code) // 'NOT_FOUND'
console.log(err.message) // 'Agent not found'
}
}
Error codes
| Code | HTTP status | Description |
|---|---|---|
UNAUTHORISED | 401 | API key is missing or invalid. |
FORBIDDEN | 403 | Key is valid but lacks permission for this action. |
NOT_FOUND | 404 | The requested resource does not exist or is not owned by your account. |
RATE_LIMIT_EXCEEDED | 429 | Too many requests. Back off and retry. |
CREDITS_EXHAUSTED | 402 | No credits remaining. Resets on the 1st of the month. |
AGENT_FROZEN | 403 | Agent is frozen. Unfreeze before running. |
POLICY_VIOLATION | 403 | Action blocked by a spending policy rule. |
APPROVAL_REQUIRED | 202 | Action requires human approval before it can proceed. |
INVALID_REQUEST | 400 | Missing or malformed request parameters. |
SERVER_ERROR | 500 | Unexpected server error. Contact support if it persists. |