SDK Installation
Install @agops-labs/sdk, point it at your AgentOps API, and pass an API key.
Install
bash
npm install @agops-labs/sdk@0.2.0
# or: pnpm add @agops-labs/sdk@0.2.0
# or: yarn add @agops-labs/sdk@0.2.00.2.0 is the current published version. The package is pre-1.0 — pin the exact version in production. See Packages & Versions for the full list of what AgentOps publishes.
Configure a client
ts
import { createAgentOpsClient } from '@agops-labs/sdk';
const client = createAgentOpsClient({
baseUrl: 'https://<your-agentops-host>', // the AgentOps API you were given
apiKey: process.env.AGENTOPS_KEY!, // sk_... or ag_...
// fetchImpl: customFetch, // optional, for tests/proxies
});baseUrl— the AgentOps API base URL. It is shown in the console; use the one matching the network you are working on.apiKey— one key per client. Usesk_for management,ag_for authorizing.fetchImpl— optional injectable fetch (defaults to global fetch).
Or configure a guarded fetch
If the agent’s job is calling paid services, createGuardedFetch is the shorter path — it handles the 402 handshake internally, so you never assemble payment headers by hand.
ts
import { createGuardedFetch } from '@agops-labs/sdk';
const guardedFetch = createGuardedFetch({
baseUrl: 'https://<your-agentops-host>',
apiKey: process.env.AGENTOPS_AGENT_KEY!, // ag_... only
agentId: 'agt_...', // must be this key's agent
});
// Use it anywhere you would use fetch.
const res = await guardedFetch('https://svc.example/paid-endpoint');Requirements
- Node.js 18+, or any runtime with a global
fetch. - ESM only — the package ships as
"type": "module". There is no CommonJS build, sorequire()will not work. - No runtime dependencies to install alongside it.
NOTE
The SDK is a client only. It runs no policy and holds no signing key locally — every call is an HTTPS request to AgentOps, which does the enforcement. That is the point: your agent process has nothing worth stealing.
Verify the install
The fastest smoke test is a decision lookup with an operator key. If it returns without an auth error, your base URL and key are correct.
ts
const status = await client.getDecision('cgd_...'); // any decision id from the console
console.log(status.outcome, status.status);Common install problems
ERR_REQUIRE_ESM— you are in a CommonJS project. Useimportin an ESM module, or a dynamicawait import().- 404 on every call —
baseUrlincludes a trailing slash or a path. Pass the origin only. - 401 — wrong key kind for the route. Management calls need
sk_;authorizeneedsag_.
