Copy-and-Paste Quickstart
Copy-paste starter snippets for ingest, import, polling, and webhooks.
Ingest object(s)
Section titled “Ingest object(s)”import Safetykit from "safetykit";
const client = new Safetykit({ apiKey: process.env.SAFETYKIT_API_KEY });
const response = await client.data.ingest("messages", { data: [ { id: "message_12345", user_id: "user_67890", text: "sample content", }, ],});
console.log(response.requestId);from safetykit import Safetykit
client = Safetykit(api_key="sk_your_api_key")
response = client.data.ingest("messages", { "data": [ { "id": "message_12345", "user_id": "user_67890", "text": "sample content" } ]})
print(response.request_id)API_KEY="sk_your_api_key"NAMESPACE="messages"
curl -X POST "https://api.safetykit.com/v1/data/${NAMESPACE}" \ -H "Authorization: Bearer ${API_KEY}" \ -H "Content-Type: application/json" \ -d '{ "data": [ { "id": "message_12345", "user_id": "user_67890", "text": "sample content" } ] }'API reference: POST /v1/data/{namespace}
Import upload flow
Section titled “Import upload flow”const importResponse = await client.data.import("messages", {});
await fetch(importResponse.upload_url, { method: "PUT", headers: { "Content-Type": "application/json" }, body: `{"id":"message_12345","text":"sample content"}\n{"id":"message_12346","text":"another message"}\n`,});
console.log(importResponse.requestId);import requests
import_response = client.data.import_("messages", {})
jsonl_payload = ( '{"id":"message_12345","text":"sample content"}\n' '{"id":"message_12346","text":"another message"}\n')
requests.put( import_response.upload_url, data=jsonl_payload.encode("utf-8"), headers={"Content-Type": "application/json"},)
print(import_response.request_id)API_KEY="sk_your_api_key"NAMESPACE="messages"
IMPORT_RESPONSE="$(curl -sS -X POST "https://api.safetykit.com/v1/data/${NAMESPACE}/import" \ -H "Authorization: Bearer ${API_KEY}" \ -H "Content-Type: application/json" \ -d '{}')"
UPLOAD_URL="$(printf '%s' "$IMPORT_RESPONSE" | jq -r '.upload_url')"REQUEST_ID="$(printf '%s' "$IMPORT_RESPONSE" | jq -r '.requestId')"
curl -X PUT "$UPLOAD_URL" \ -H "Content-Type: application/json" \ --data-binary @data.jsonl
echo "Import started: ${REQUEST_ID}"API reference: POST /v1/data/{namespace}/import
Poll request status
Section titled “Poll request status”async function waitForCompletion(namespace: string, requestId: string) { while (true) { const status = await client.data.getStatus(namespace, requestId); if (status.status === "succeeded" || status.status === "failed") { return status; } await new Promise((resolve) => setTimeout(resolve, 5000)); }}import time
def wait_for_completion(namespace: str, request_id: str): while True: status = client.data.get_status(namespace, request_id) if status.status in ("succeeded", "failed"): return status time.sleep(5)API reference: GET /v1/data/{namespace}/requests/{requestId}
Verify webhook signature
Section titled “Verify webhook signature”import { Webhook } from "svix";
const verifier = new Webhook(process.env.SAFETYKIT_WEBHOOK_SECRET!);
const payload = verifier.verify(rawBody, { "webhook-id": req.headers["webhook-id"] as string, "webhook-timestamp": req.headers["webhook-timestamp"] as string, "webhook-signature": req.headers["webhook-signature"] as string,});from svix.webhooks import Webhook
verifier = Webhook("whsec_your_signing_secret")payload = verifier.verify(raw_body, request_headers)API reference: Verifying Signatures
Handle workflow completion event
Section titled “Handle workflow completion event”if (event.type === "workflow.succeeded" && event.namespace === "messages") { const { id, output } = event; await handleReviewDecision(id, output);}API reference: workflow.succeeded event