retry-job
Requeue a failed or timed-out Serverless job by removing its previous output and resetting its status to pending.
Instructions
Retry a failed or timed-out Serverless job. Only works for jobs with FAILED or TIMED_OUT status. The previous output is removed and the job is requeued.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| endpointId | Yes | ID of the Serverless endpoint the job belongs to | |
| jobId | Yes | ID of the job to retry |
Implementation Reference
- src/index.ts:994-1017 (handler)The 'retry-job' tool handler registered via server.tool(). It takes endpointId and jobId as params, calls the RunPod Serverless API POST /retry/:jobId endpoint, and returns the JSON result.
server.tool( 'retry-job', 'Retry a failed or timed-out Serverless job. Only works for jobs with FAILED or TIMED_OUT status. The previous output is removed and the job is requeued.', { endpointId: endpointIdSchema.describe('ID of the Serverless endpoint the job belongs to'), jobId: jobIdSchema.describe('ID of the job to retry'), }, async (params) => { const result = await serverlessRequest( params.endpointId, `/retry/${params.jobId}`, 'POST' ); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2), }, ], }; } ); - src/index.ts:997-1000 (schema)Input schema for retry-job: endpointId (endpointIdSchema) and jobId (jobIdSchema), both validated as alphanumeric strings with regex.
{ endpointId: endpointIdSchema.describe('ID of the Serverless endpoint the job belongs to'), jobId: jobIdSchema.describe('ID of the job to retry'), }, - src/index.ts:747-749 (schema)Definition of endpointIdSchema: a Zod string validated with regex /^[a-zA-Z0-9_-]+$/.
const endpointIdSchema = z .string() .regex(/^[a-zA-Z0-9_-]+$/, 'Invalid endpoint ID format'); - src/index.ts:751-753 (schema)Definition of jobIdSchema: a Zod string validated with regex /^[a-zA-Z0-9_-]+$/.
const jobIdSchema = z .string() .regex(/^[a-zA-Z0-9_-]+$/, 'Invalid job ID format'); - src/index.ts:277-318 (helper)The serverlessRequest helper function that makes authenticated HTTP requests to the RunPod Serverless runtime API (api.runpod.ai/v2). Used by the retry-job handler to POST to /retry/:jobId.
async function serverlessRequest( endpointId: string, path: string, method: string = 'GET', body?: Record<string, unknown> ) { const url = `${SERVERLESS_API_BASE_URL}/${endpointId}${path}`; const headers: Record<string, string> = { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json', }; const options: NodeFetchRequestInit = { method, headers, }; if (body && (method === 'POST' || method === 'PATCH')) { options.body = JSON.stringify(body); } try { const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); throw new Error( `RunPod Serverless API Error: ${response.status} - ${errorText}` ); } const contentType = response.headers.get('content-type'); if (contentType && contentType.includes('application/json')) { return await response.json(); } return { success: true, status: response.status }; } catch (error) { console.error('Error calling RunPod Serverless API:', error); throw error; } }