Skip to content

ReqRun/reqrun-example-nextjs-route-handler

Repository files navigation

ReqRun with Next.js Route Handlers

Runnable Next.js App Router example that submits OpenAI-compatible work through ReqRun instead of calling the model provider directly.

What this repo shows

  • a browser form talking to local Next.js route handlers
  • a route handler that submits work to POST /v1/chat/completions
  • a second route handler that proxies GET /v1/requests/{id}
  • idempotency keys and async request ids without exposing the ReqRun API key to the browser

Why this is client-only

This repo does not contain ReqRun backend code. It is only a thin app-side integration that talks to the hosted ReqRun API at https://api.reqrun.com.

Prerequisites

Setup

  1. Copy the env template:
cp .env.example .env.local
  1. Fill in:
REQRUN_API_KEY=REQRUN_LIVE_YOUR_PROJECT_KEY_HERE
REQRUN_BASE_URL=https://api.reqrun.com
  1. Install dependencies:
npm install
  1. Run the app:
npm run dev
  1. Open http://localhost:3000

Run flow

The page sends your prompt to /api/run, which then sends this payload to ReqRun:

{
  "model": "gpt-5-nano",
  "messages": [
    { "role": "system", "content": "Return concise, useful output." },
    { "role": "user", "content": "Your prompt here" }
  ],
  "wait": false,
  "idempotency_key": "nextjs-demo-job-001"
}

When ReqRun returns an async response, the page can then call /api/requests/{id} to fetch the durable status by request id.

ReqRun docs

About

Durable OpenAI-compatible request handoff from a Next.js route handler.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors