Back to blog

Fusion API Python example (OpenRouter)

Call the OpenRouter Fusion API from Python using the openai SDK: a minimal example, streaming, and a custom panel via extra_body — copy-paste ready.

Jun 15, 2026FusionAPIFusionAPI
Fusion API Python example (OpenRouter)

Because the Fusion API is OpenAI-compatible, the fastest way to call it from Python is the official openai SDK pointed at OpenRouter's base URL. (For the request shape in general, see how to call the Fusion API.)

Install

pip install openai

Minimal example

from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key="sk-or-...",  # your OpenRouter key
)

resp = client.chat.completions.create(
    model="openrouter/fusion",
    messages=[
        {"role": "user", "content": "Compare Postgres vs SQLite for a serverless SaaS."}
    ],
)

print(resp.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
    model="openrouter/fusion",
    messages=[{"role": "user", "content": "..."}],
    stream=True,
)

for chunk in stream:
    delta = chunk.choices[0].delta.content
    if delta:
        print(delta, end="", flush=True)

Custom panel + judge

The openai SDK doesn't have a native plugins parameter, so pass it through extra_body:

resp = client.chat.completions.create(
    model="openrouter/fusion",
    messages=[{"role": "user", "content": "..."}],
    extra_body={
        "plugins": [{
            "id": "fusion",
            "model": "google/gemini-3-flash-preview",  # judge / synthesizer
            "analysis_models": [                          # the panel
                "google/gemini-3-flash-preview",
                "moonshotai/kimi-k2.6",
                "deepseek/deepseek-v4-pro",
            ],
        }]
    },
)

Tips

  • Set the key from an environment variable (os.environ["OPENROUTER_API_KEY"]) — never hard-code it.
  • A Fusion call bills as the sum of the panel plus the judge, so it costs more than one model. Estimate it first with the cost calculator.
  • Want to eyeball the output before coding? Run it in the Playground. Next: the Node.js version.