Integrations
Next.js
Call the Apertis API from a Next.js App Router route handler with the OpenAI SDK.
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 openaiSet 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-keyMinimal 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
- Quick Start: create an account and your first request
- API Keys: create and rotate keys
- Chat Completions: every request field
- Messages API: the Anthropic-style endpoint
- Error codes: a
401means the key is missing or wrong