Developer
SDKs
WeaveOS provides official SDKs for Node.js and Python, plus full cURL examples for direct API integration.
Node.js
Install
bash
npm install @weaveos/sdkInitialise
javascript
import WeaveOS from "@weaveos/sdk";
const client = new WeaveOS({
apiKey: process.env.WEAVEOS_API_KEY, // sk_live_... or sk_test_...
timeout: 30_000, // ms, default 30s
});Workflows
javascript
// Create
const wf = await client.workflows.create({
product: "ticket_resolution_v2",
customerId: "cus_acme_prod_01",
payload: { ticketId: "TKT-8821" },
});
// Fetch
const wf = await client.workflows.fetch("wf_e4rgffg44fg4g44");
// List (paginated)
const page = await client.workflows.list({ status: "Settled", limit: 25 });
for (const wf of page.data) {
console.log(wf.id, wf.margin.achieved);
}
// Auto-paginate all
for await (const wf of client.workflows.listAutoPaging({ status: "Settled" })) {
console.log(wf.id);
}Webhooks
javascript
// Verify and parse an incoming webhook
const event = client.webhooks.construct(
rawBody, // Buffer or string
req.headers["weaveos-signature"], // Signature header
process.env.WEBHOOK_SECRET // Your endpoint secret
);
console.log(event.type); // "workflow.completed"
console.log(event.data.workflowId); // "wf_e4rgffg44fg4g44"Python
Install
bash
pip install weaveosInitialise
python
import weaveos
import os
client = weaveos.WeaveOS(api_key=os.environ["WEAVEOS_API_KEY"])Workflows
python
# Create
wf = client.workflows.create(
product="ticket_resolution_v2",
customer_id="cus_acme_prod_01",
payload={"ticket_id": "TKT-8821"},
)
print(wf.id) # wf_e4rgffg44fg4g44
print(wf.quoted.amount) # 0.12
# Fetch
wf = client.workflows.fetch("wf_e4rgffg44fg4g44")
# List
page = client.workflows.list(status="Settled", limit=25)
for wf in page.data:
print(wf.id, wf.margin.achieved)
# Auto-paginate
for wf in client.workflows.list_auto_paging(status="Settled"):
print(wf.id)Webhooks
python
from flask import Flask, request
app = Flask(__name__)
@app.route("/webhooks/weaveos", methods=["POST"])
def webhook():
sig = request.headers.get("weaveos-signature")
try:
event = client.webhooks.construct(
request.data,
sig,
os.environ["WEBHOOK_SECRET"],
)
except weaveos.SignatureVerificationError:
return "Bad signature", 400
if event.type == "workflow.completed":
print("Settled:", event.data.workflow_id)
print("Margin:", event.data.margin.achieved)
return {"received": True}cURL
All endpoints are accessible via plain HTTP. Use cURL for quick exploration or in environments without a supported SDK.
Create a workflow
bash
curl https://api.weaveos.dev/v1/workflows \
-X POST \
-H "Authorization: Bearer $WEAVEOS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"product": "ticket_resolution_v2",
"customerId": "cus_acme_prod_01",
"payload": { "ticketId": "TKT-8821" }
}'List workflows
bash
curl "https://api.weaveos.dev/v1/workflows?status=Settled&limit=10" \
-H "Authorization: Bearer $WEAVEOS_API_KEY"Fetch a workflow
bash
curl https://api.weaveos.dev/v1/workflows/wf_e4rgffg44fg4g44 \
-H "Authorization: Bearer $WEAVEOS_API_KEY"TipSet
WEAVEOS_API_KEY as a shell variable to avoid repeating it across cURL commands: export WEAVEOS_API_KEY=sk_test_...Error handling
All SDKs throw typed errors. Catch them specifically for robust error handling:
javascript
import WeaveOS, { APIError, AuthenticationError, RateLimitError } from "@weaveos/sdk";
try {
const wf = await client.workflows.create({ ... });
} catch (err) {
if (err instanceof AuthenticationError) {
console.error("Invalid API key");
} else if (err instanceof RateLimitError) {
const retryAfter = err.headers["retry-after"];
console.error(`Rate limited. Retry after ${retryAfter}s.`);
} else if (err instanceof APIError) {
console.error(`API error ${err.status}: ${err.message}`);
} else {
throw err;
}
}