Use Flux with LlamaIndex
Point LlamaIndex's OpenAI LLM at FluxRouter with a custom api_base and your Flux key.
LlamaIndex talks to FluxRouter through its OpenAI LLM. Because Flux is OpenAI-compatible, you use the OpenAI LLM class and set api_base to https://api.fluxrouter.ai/v1, your Flux key, and the model to flux-auto.
Set up the OpenAI LLM to use Flux
Install the LlamaIndex OpenAI integration (pip install llama-index-llms-openai), then point the LLM at Flux:
from llama_index.llms.openai import OpenAI
llm = OpenAI(
model="flux-auto", # let Flux route, or pin a flux-* id
api_key="sk-...", # your Flux key
api_base="https://api.fluxrouter.ai/v1", # the one line that points at Flux
)
response = llm.complete("Say hello from FluxRouter.")
print(response.text)
api_base is the documented parameter on the LlamaIndex OpenAI LLM for a custom OpenAI-compatible endpoint.
Read the key from the environment
import os
from llama_index.llms.openai import OpenAI
llm = OpenAI(
model="flux-auto",
api_key=os.environ["FLUX_API_KEY"],
api_base="https://api.fluxrouter.ai/v1",
)
Use it as the default LLM
Set Flux as the global LLM through Settings, and the rest of LlamaIndex (query engines, agents, indexes) uses it automatically:
from llama_index.core import Settings
Settings.llm = llm
Pick a model
flux-auto routes each request for you. To pin a model, swap the model value for a tier alias (flux-fast, flux-standard, flux-reasoning) or a flux-pinned-* id. See Models.