Job Management
Poll Job Status
Section titled “Poll Job Status”GET /agent/job/:jobId
Job States
Section titled “Job States”| State | Description |
|---|---|
pending | Job is queued, waiting to be processed |
processing | Job is actively being executed |
completed | Job finished successfully |
failed | Job encountered an error |
cancelled | Job was cancelled by the user |
Examples
Section titled “Examples”curl https://api.bankr.bot/agent/job/job_abc123 \ -H "X-API-Key: bk_YOUR_KEY"async function pollJob(jobId: string, apiKey: string) { const BASE_URL = "https://api.bankr.bot";
while (true) { const job = await fetch(`${BASE_URL}/agent/job/${jobId}`, { headers: { "X-API-Key": apiKey }, }).then(r => r.json());
if (job.status === "completed") return job; if (job.status === "failed") throw new Error(job.error); if (job.status === "cancelled") throw new Error("Job cancelled");
// Wait 2 seconds before polling again await new Promise(r => setTimeout(r, 2000)); }}Completed Response
Section titled “Completed Response”{ "status": "completed", "response": "Successfully swapped 0.001 ETH for 3.21 USDC on Base.", "metadata": { "transactionHash": "0x...", "chain": "base" }}Failed Response
Section titled “Failed Response”{ "status": "failed", "error": "Insufficient balance for this transaction."}Cancel a Job
Section titled “Cancel a Job”DELETE /agent/job/:jobId
Cancel a job that is still pending or processing. Once a job reaches a terminal state (completed, failed, or cancelled), it can no longer be cancelled.
curl -X DELETE https://api.bankr.bot/agent/job/job_abc123 \ -H "X-API-Key: bk_YOUR_KEY"Recommended Polling Strategy
Section titled “Recommended Polling Strategy”- Poll every 2 seconds. This provides a good balance between responsiveness and staying within rate limits.
- Set a timeout (for example, 60 seconds) to avoid infinite loops if a job gets stuck.
- Handle all terminal states:
completed,failed, andcancelled. Your code should have a clear path for each.