Skip to content

Python basic with Poetry

Smallest SDK example

This is the smallest runnable LunarGate example. It is intentionally very close to the homepage snippet, but turned into a real project with `.env`, a real `main.py`, and a gateway config you can run locally.

Use this example when:

  • you already know the OpenAI Python SDK
  • you want the smallest possible diff from direct OpenAI usage
  • you do not need streaming, UI, or multi-container orchestration yet

What it demonstrates

  • OpenAI(base_url=...) pointed at the gateway
  • one chat.completions.create(...) request
  • .env-driven local configuration
  • a minimal single-provider gateway config

Run it

cp .env.example .env
poetry install

Start the gateway in a separate terminal:

cp config-simple.yaml.example config.yaml
lunargate --config ./config.yaml

Then run the client:

poetry run python main.py

What to inspect

  • .env.example for client-side defaults
  • config-simple.yaml.example for the smallest working gateway config
  • main.py for the minimal OpenAI SDK integration

Why this example matters

This is the shortest path from:

  • direct OpenAI client usage

To:

  • the same SDK talking to LunarGate instead

If you already have a Python service and do not need streaming, UI, or multi-container orchestration yet, this is the right place to start.

Next step after this example

  1. Move to Docker Compose minimal if you want the gateway and app in one local demo.
  2. Move to Python lunargate/auto demo if you want the gateway to choose model tiers for you.