ESC
NextStarterAI logo
Menu
On this page

Features > Runpod Integration

Deploying to Runpod is a breeze. You can deploy your models on serverless platform, make an endpoint and start making requests to your model in no time. 🚀


Check out the AI Services tutorial to learn how to deploy your custom AI models on Runpod.


Grab your model's endpoint url on Runpod and modify your api/ai/runpod/route.ts to make requests to your model inside your NextStarter project.


api/ai/runpod/route.ts
1 2 let data = JSON.stringify({ // Modify the data object to match the request body of your API 3 input: { 4 image: base64, 5 prompt: requestBody.prompt, 6 seed: requestBody.seed, 7 style: requestBody.style, 8 }, 9 }); 10 11 let config = { 12 method: "post", 13 maxBodyLength: Infinity, 14 url: "#YOUR_RUNPOD_ENDPOINT#", // place in your endpoint here or use environment variables 15 headers: { 16 Authorization: "Bearer #YOUR_RUNPOD_API_KEY#", // place in your API key here or use environment variables 17 "Content-Type": "application/json", 18 }, 19 data: data, 20 }; 21 22 23 .... 24 25 try { 26 // Custom retry logic to handle failed AI requests 27 axiosRetry(axios, { 28 retryDelay: (retryCount) => { 29 return retryCount * 1; 30 }, 31 retries: 15, 32 }); 33 34 const result = await axios.request(config); 35 if (result.status === 200) { 36 return NextResponse.json(result.data); 37 } else { 38 return NextResponse.json(result.data, { status: result.status }); 39 } 40 } catch (error) { 41 return NextResponse.json(error.response.data, { 42 status: error.response.status, 43 }); 44 } 45

Input Type

We've used base64 encoding for the image input, as it's the most common use case for image generation models.
Modify the input type to match the request body of your API, if your model requires different input types.