Integrations

Flask

Call the Apertis API from a Flask route with the OpenAI Python SDK.

Updated
Reading time
1 min

On this page

Add a /chat route to a Flask app that returns a chat completion from Apertis, using the OpenAI Python SDK.

Install

pip install openai flask

Set your API key

Create a key in Settings → API Keys, then export it:

export APERTIS_API_KEY="sk-your-api-key"

Minimal app

app.py:

import os

from flask import Flask, jsonify, request
from openai import OpenAI

app = Flask(__name__)
client = OpenAI(
    base_url="https://api.apertis.ai/v1",
    api_key=os.environ["APERTIS_API_KEY"],
)


@app.get("/chat")
def chat():
    q = request.args.get("q", "Hello! What can you do?")
    completion = client.chat.completions.create(
        model="gpt-5.5",
        messages=[{"role": "user", "content": q}],
    )
    return jsonify(text=completion.choices[0].message.content)

Run and test

flask --app app run --port 8000
curl "http://127.0.0.1:8000/chat?q=Say+hi"

The app runs on port 8000 because macOS reserves Flask's default port 5000 for AirPlay Receiver.

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

Next steps