Skip to main content

Quickstart

1. Install​

litellm.agent() is part of the regular litellm package and adds no dependencies to it. Install what your harness needs:

HarnessPython packagesRuntime on the sandbox's PATH
Claude Codepip install litellm starlette uvicornnpm install -g @anthropic-ai/claude-code
Codexpip install litellm starlette uvicornnpm install -g @openai/codex
OpenCodepip install litellm starlette uvicornnpm install -g opencode-ai
Deep Agentspip install litellm deepagents langchain-litellm (Python 3.11+)nothing

starlette and uvicorn run the small per-session model endpoint the CLI harnesses call. If something is missing, the call raises HarnessInstallFailed with the exact install command.

2. Point at your gateway​

Use a virtual key from your LiteLLM AI Gateway. It stays on your host. Models prefixed with litellm_proxy/ are sent to this gateway.

export LITELLM_PROXY_API_BASE=https://litellm.example.com
export LITELLM_PROXY_API_KEY=sk-...

To skip the gateway, export a provider key such as ANTHROPIC_API_KEY instead and use a model string without the prefix, like anthropic/claude-sonnet-4-5.

3. Run one turn​

fix_flaky.py
import litellm
from litellm import Harness, sandbox

result = litellm.agent(
Harness.CLAUDE_CODE,
"Find why tests/test_router.py is flaky and fix it.",
sandbox=sandbox.local("./repo"),
model="litellm_proxy/coder",
)

print(result.text)
print(f"${result.cost:.4f}")

Permissions default to "full", because the sandbox is the boundary. Use permissions="read-only" for reviews, or a Docker sandbox for code you don't trust.

4. Stream events​

from litellm import Harness
from litellm.harness import Text, FileChange, Done

for event in litellm.agent(stream=True,
Harness.CODEX,
"Add type hints to utils.py",
sandbox=sandbox.local("./repo"),
model="litellm_proxy/coder",
):
match event:
case Text(delta=delta):
print(delta, end="", flush=True)
case FileChange(path=path):
print(f"\n changed {path}")
case Done(cost=cost):
print(f"\n${cost:.4f}")
case _:
pass

5. Pick a harness​

Every harness takes the same call, but each suits different work and a different kind of model group. Choosing a harness covers when to use which, and the gateway tags every request with the harness that made it, so you can compare their spend.

LiteLLM Enterprise
SSO/SAML, audit logs, spend tracking, multi-team management, and guardrails, built for production.
Learn more →