Integrations

Next.js

Call the Apertis API from a Next.js App Router route handler with the OpenAI SDK.

Updated
Reading time
1 min

On this page

Add an App Router Route Handler that returns a chat completion from Apertis, using the OpenAI Node SDK.

Install

npx create-next-app@latest my-app --ts --app
cd my-app
npm install openai

Set your API key

Put the key in .env.local. Do not prefix it with NEXT_PUBLIC_: that would ship it to the browser.

.env.local:

APERTIS_API_KEY=sk-your-api-key

Minimal route

app/api/chat/route.ts:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.apertis.ai/v1",
  apiKey: process.env.APERTIS_API_KEY,
});

export async function GET(request: Request) {
  const q =
    new URL(request.url).searchParams.get("q") ?? "Hello! What can you do?";
  const completion = await client.chat.completions.create({
    model: "gpt-5.5",
    messages: [{ role: "user", content: q }],
  });
  return Response.json({ text: completion.choices[0].message.content });
}

The route runs on the server, so the key is never sent to the client.

Run and test

npm run dev
curl "http://localhost:3000/api/chat?q=Say+hi"

The SDK sends Authorization: Bearer with your key to https://api.apertis.ai/v1. Pick any model ID from the Models page.

Next steps