Skip to main content

Job Management

After submitting a prompt, use these endpoints to track and manage your jobs.

Get Job Status​

GET /agent/job/{jobId}

Headers​

HeaderValueRequired
X-API-KeyYour API keyYes

Path Parameters​

ParameterTypeDescription
jobIdstringJob identifier from submit prompt response

Response (200 OK)​

{
"success": true,
"jobId": "abc123",
"threadId": "thr_XYZ789",
"status": "completed",
"prompt": "what is the price of ETH?",
"createdAt": "2024-01-15T10:30:00Z",
"completedAt": "2024-01-15T10:30:03Z",
"processingTime": 3000,
"response": "ETH is currently trading at $3,245.67",
"richData": [],
"cancellable": false
}

Response Fields​

FieldTypeDescriptionWhen Present
successbooleanWhether the request succeededAlways
jobIdstringJob identifierAlways
threadIdstringConversation thread IDWhen set
statusJobStatusCurrent job statusAlways
promptstringOriginal prompt submittedAlways
createdAtstringISO 8601 timestampAlways
cancellablebooleanWhether job can be cancelledpending/processing
statusUpdatesStatusUpdate[]Progress messagesWhen available
startedAtstringWhen processing startedprocessing
responsestringAI agent's responsecompleted
richDataRichData[]Additional structured datacompleted
completedAtstringWhen job finishedcompleted/failed
processingTimenumberDuration in millisecondscompleted
errorstringError messagefailed
cancelledAtstringWhen job was cancelledcancelled

This endpoint never returns a transactions array; when the agent executed transactions, response and richData describe them.

Job Status Values​

StatusDescription
pendingJob is queued for processing
processingJob is currently being processed
completedJob finished successfully
failedJob encountered an error
cancelledJob was cancelled by user

Error Responses​

Job ID Required (400)

{
"error": "Job ID required",
"message": "Please provide a job ID"
}

Job Not Found (404)

{
"error": "Job not found",
"message": "Job not found or you don't have permission to access it"
}

Cancel Job​

POST /agent/job/{jobId}/cancel

Cancel a pending or processing job.

Headers​

HeaderValueRequired
X-API-KeyYour API keyYes

Path Parameters​

ParameterTypeDescription
jobIdstringJob identifier to cancel

Response (200 OK)​

{
"success": true,
"jobId": "abc123",
"status": "cancelled",
"prompt": "swap $100 ETH to USDC",
"createdAt": "2024-01-15T10:30:00Z",
"cancelledAt": "2024-01-15T10:30:05Z"
}
note

Cancel requests are idempotent. Cancelling an already-cancelled job returns success.

Error Responses​

Job Already Completed (400)

{
"success": false,
"error": "Job already completed",
"message": "Cannot cancel a job that has already completed"
}

Job Already Failed (400)

{
"success": false,
"error": "Job already failed",
"message": "Cannot cancel a job that has already failed"
}

Polling Strategy​

ParameterRecommendedNotes
Interval2 secondsBalance between responsiveness and API load
Max attempts150~5 minutes, the same budget the Bankr CLI uses
Total timeout5 minutes or moreMost jobs complete within 30 seconds; launches, leveraged trades and cross-chain swaps take longer

Complete Example​

const API_BASE_URL = "https://api.bankr.bot/agent";
const API_KEY = process.env.BANKR_API_KEY!;

async function executePrompt(prompt: string) {
// 1) Submit the prompt
const submitResponse = await fetch(`${API_BASE_URL}/prompt`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-API-Key": API_KEY,
},
body: JSON.stringify({ prompt }),
});

if (!submitResponse.ok) {
const error = await submitResponse.json();
throw new Error(error.message || "Failed to submit prompt");
}

const { jobId } = await submitResponse.json();
console.log(`Job submitted: ${jobId}`);

// 2) Poll for completion
const result = await pollForCompletion(jobId);
return result;
}

async function pollForCompletion(jobId: string, maxAttempts = 150) {
for (let i = 0; i < maxAttempts; i++) {
const statusResponse = await fetch(`${API_BASE_URL}/job/${jobId}`, {
headers: { "X-API-Key": API_KEY },
});

if (!statusResponse.ok) {
throw new Error("Failed to fetch job status");
}

const job = await statusResponse.json();
console.log(`Status: ${job.status}`);

if (job.status === "completed") {
return {
response: job.response,
richData: job.richData,
};
}

if (job.status === "failed") {
throw new Error(job.error || "Job failed");
}

if (job.status === "cancelled") {
throw new Error("Job was cancelled");
}

// Wait 2 seconds before next poll
await new Promise((resolve) => setTimeout(resolve, 2000));
}

throw new Error("Timeout waiting for job completion");
}

async function cancelJob(jobId: string) {
const response = await fetch(`${API_BASE_URL}/job/${jobId}/cancel`, {
method: "POST",
headers: { "X-API-Key": API_KEY },
});

if (!response.ok) {
const error = await response.json();
throw new Error(error.message || "Failed to cancel job");
}

return response.json();
}

// Usage
async function main() {
const result = await executePrompt("What is the current price of ETH?");
console.log("Response:", result.response);
console.log("Rich Data:", result.richData);
}

main().catch(console.error);

Rich Data​

Completed jobs may include richData: structured items the agent attached, each with a type — for example a price chart or an image with its URL:

{
"richData": [
{
"type": "chart",
"url": "https://..."
}
]
}

The set of types can grow, so ignore types your client doesn't handle.