Skip to content

Python lunargate/auto demo

This example demonstrates one of the most LunarGate-specific patterns: the client always sends model="lunargate/auto", and the gateway picks a tier based on the request.

Best for

Use this example when you want to understand autorouting before rolling it into a real application.

What it demonstrates

  • a stable client-side model ID: lunargate/auto
  • model_selection scoring and tier headers
  • routing different requests to light, balanced, and heavy models
  • tool-aware routes that can override normal complexity-tier routing
  • OpenAI-compatible chat.completions as the client-facing API
  • reading X-LunarGate-* headers to see what the gateway decided

Default tier mapping in the example

  • light: gpt-5.4-nano
  • balanced: gpt-5.4-mini
  • heavy: gpt-5.4

You can change those model names in .env without touching application code.

Run it

cp .env.example .env
poetry install

Start the gateway separately:

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

Then run the demo:

poetry run python main.py

This example intentionally stays on POST /v1/chat/completions. It does not require the Responses API path.

What you will see

The script sends multiple requests with different complexity and tool usage.

After each request it prints:

  • the selected provider
  • the selected model
  • the calculated complexity tier
  • either the response content or generated tool calls

Important design detail

This example sets weight_tools = 0 in the scoring config.

That is a demo choice, not a universal recommendation. It keeps tool-bearing requests from automatically looking more complex just because they include tools, which makes it easier to show multiple tiers in one short demo run.

What to inspect

  • config-simple.yaml.example for tier routes and model_selection
  • .env.example for light/balanced/heavy model variables
  • main.py for the stable lunargate/auto client model
  • config-observability.yaml.example if you want the same demo with data_sharing and remote control enabled