@problee/sdk
v0.1.2
Published
TypeScript SDK for the Problee Agent API. Discover markets, get quotes, prepare trades, subscribe to events.
Maintainers
Readme
@problee/sdk
TypeScript SDK for the Problee Agent API.
v0.1.0 is hand-typed for the highest-traffic endpoints. v1.0.0 will be auto-generated from the OpenAPI spec at https://api.problee.com/api/agent/v1/openapi.json — types perfectly in sync with the protocol. Watch the changelog for the upgrade.
Install
npm install @problee/sdk
# or
pnpm add @problee/sdkZero runtime dependencies. Node 18+ (uses native fetch).
Get an API key
https://problee.com/developer/register-agent
Or use the @problee/mcp CLI:
npx @problee/mcp registerUsage
import { ProbleeClient } from "@problee/sdk";
const client = new ProbleeClient({ apiKey: process.env.PROBLEE_API_KEY! });
// Who am I?
const me = await client.me();
console.log(me.tier, me.scopes);
// Discover live markets
const { markets } = await client.markets.list({ lifecycle: "live", limit: 10 });
// Get a quote
const quote = await client.trade.quote({
marketAddress: "0x...",
outcome: 1,
side: "buy",
amount: "100",
});
console.log(`Price ${quote.price}, slippage ${quote.slippageBps}bps`);
// Prepare a trade (returns a calldata payload to sign)
const prepared = await client.trade.prepare({
marketAddress: "0x...",
outcome: 1,
side: "buy",
amount: "100",
walletAddress: "0xYourWallet",
slippageBps: 100,
});
// Sign and broadcast `prepared.call` with your wallet client of choiceCoverage in v0.1.0
| Method | Endpoint |
|---|---|
| client.me() | GET /me |
| client.markets.list(params?) | GET /discover/markets |
| client.markets.get(address) | GET /discover/markets/{address} |
| client.markets.chart(address, params?) | GET /discover/markets/{address}/chart |
| client.trade.quote(body) | POST /trade/quote |
| client.trade.prepare(body) | POST /trade/prepare |
| client.events.types() | GET /events/types |
| client.events.subscribe(types?) | GET /events/subscribe (SSE) |
| client.auth.deviceCode(params?) | POST /authorizations/device |
| client.auth.deviceToken(code) | POST /authorizations/token |
| client.request<T>(method, path, body?) | escape hatch — typed fetch over any endpoint |
For everything else, use client.request() until v1.0.0 lands. The escape hatch returns whatever the server sends, validated as JSON.
Streaming events (SSE)
const res = await client.events.subscribe(["market.created", "trade.executed"]);
const reader = res.body!.getReader();
const decoder = new TextDecoder();
while (true) {
const { value, done } = await reader.read();
if (done) break;
// Parse the SSE chunks — each event is `event: name\ndata: {...}\n\n`
console.log(decoder.decode(value));
}Device-code auth (no API key in env)
For CLI tools that don't want users to copy/paste an API key:
import { ProbleeClient } from "@problee/sdk";
// Use a starter client with no key (just to discover endpoints), then upgrade
const starter = new ProbleeClient({ apiKey: "anonymous" });
const code = await starter.auth.deviceCode({ clientName: "my-cli", scopes: ["markets:read"] });
console.log(`Visit ${code.verification_uri} and enter ${code.user_code}`);
// Poll for completion
let token: string | undefined;
while (!token) {
await new Promise((r) => setTimeout(r, code.interval * 1000));
const res = await starter.auth.deviceToken(code.device_code);
if (res.access_token) token = res.access_token;
else if (res.error && res.error !== "authorization_pending" && res.error !== "slow_down") {
throw new Error(`auth failed: ${res.error}`);
}
}
// Now use it
const client = new ProbleeClient({ apiKey: token });Errors
All non-2xx responses throw ProbleeError:
import { ProbleeClient, ProbleeError } from "@problee/sdk";
try {
await client.trade.quote(...);
} catch (err) {
if (err instanceof ProbleeError) {
console.error(err.status, err.code, err.requestId);
console.error(err.body); // full RFC 7807 problem+json body
}
}Required scopes per endpoint
| Capability | Required API-key scope |
|---|---|
| List chains, read public metadata | none |
| Read markets and events | markets:read |
| Quote trades | trade:quote |
| Create markets | markets:create |
| Prepare or execute trades | trade:execute |
| Read portfolio and fees | portfolio:read |
| Manage webhooks | webhooks:manage |
Companion packages
@problee/mcp— installer for the Problee MCP server in Claude Desktop / Cursor / Codex@problee/ai— Vercel AI SDK provider that exposes Problee tools togenerateText/streamText
Links
- Live API: https://api.problee.com/api/agent/v1/
- OpenAPI spec: https://api.problee.com/api/agent/v1/openapi.json
- Agent docs: https://problee.com/developer
- Source: https://github.com/probleeprotocol/problee/tree/main/sdk/typescript/sdk
License
MIT
