LiteLLM OpenAI Basic
Run GPT-5.6 Luna through a LiteLLM proxy server with sync and streaming responses.
OPENAI_API_KEY belongs to the upstream OpenAI account. LITELLM_API_KEY is the agent client's proxy bearer value: local-proxy is a placeholder for this local server, which has no authentication configured by these commands. If you configure proxy authentication, supply its accepted key instead. Exporting a client key alone does not configure server authentication.
"""
Litellm Openai Basic
====================
Cookbook example for `litellm_openai/basic.py`.
"""
from agno.agent import Agent, RunOutput # noqa
from agno.models.litellm import LiteLLMOpenAI
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(model=LiteLLMOpenAI(id="gpt-5.6-luna"), markdown=True)
# Get the response in a variable
# run: RunOutput = agent.run("Share a 2 sentence horror story")
# print(run.content)
# Print the response in the terminal
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
# --- Sync ---
agent.print_response("Share a 2 sentence horror story")
# --- Sync + Streaming ---
agent.print_response("Share a 2 sentence horror story", stream=True)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno "litellm[proxy]" openaiExport your API keys
export LITELLM_API_KEY="local-proxy"
export OPENAI_API_KEY="your_openai_api_key_here"Start LiteLLM
In the first terminal, with OPENAI_API_KEY set, start the proxy below and leave it running:
litellm --model gpt-5.6-luna --host 127.0.0.1 --port 4000Point the client at the local proxy
Add base_url="http://127.0.0.1:4000" to LiteLLMOpenAI(...) in the saved file. In a second terminal, activate the same virtual environment and set LITELLM_API_KEY as above before running the agent. The foreground proxy uses the model selected by its CLI command.
Run the example
Save the code above as basic.py, then run:
python basic.pyFull source: cookbook/90_models/litellm_openai/basic.py