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

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": "No job found with ID abc123"
}

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 completed job"
}

Job Already Failed (400)

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

Polling Strategy

async function pollForCompletion(jobId: string, maxAttempts = 60) {
const API_KEY = process.env.BANKR_API_KEY;

for (let i = 0; i < maxAttempts; i++) {
const response = await fetch(
`https://api.bankr.bot/agent/job/${jobId}`,
{
headers: { 'X-API-Key': API_KEY },
}
);

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

const job = await response.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');
}

Polling Parameters

ParameterRecommendedNotes
Interval2 secondsBalance between responsiveness and API load
Max attempts60~2 minutes total timeout
Total timeout2-5 minutesMost jobs complete within 30 seconds

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 = 60) {
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 with additional structured information:

{
"richData": [
{
"type": "token_info",
"symbol": "ETH",
"price": 3245.67,
"change24h": 2.3
},
{
"type": "chart",
"url": "https://..."
}
]
}

The structure varies based on the type of query and response.