LiteLLM Integration with The Grid | SDK and Proxy Setup
Use LiteLLM with The Grid as an OpenAI-compatible backend. Connect through the Python SDK or proxy and route downstream tools.
LiteLLM normalizes 100+ LLM providers to the OpenAI format. The Grid plugs in as an OpenAI-compatible backend. You can call The Grid directly from the litellm Python SDK, or run the LiteLLM proxy in front of The Grid so any downstream OpenAI-compatible tool routes through a single endpoint.
Quick version. Prefix Grid models with
openai/so LiteLLM uses its OpenAI-compatible client. Setapi_base: https://api.thegrid.ai/v1andapi_key: os.environ/THEGRID_API_KEY. For the proxy, runuv run litellm --config config.yaml.
For the full instrument catalog, see Current instruments.
Two patterns
SDK. Your Python app calls
litellm.completion(...)with The Grid as a backend. LiteLLM handles retries, fallbacks, and response normalization.Proxy. Run
uv run litellm --config config.yamlas a standalone server. All your agents, IDEs, and scripts point at the proxy. The proxy fans out to The Grid (and optionally OpenAI, Anthropic, local models) from onemodel_list.
In both patterns, The Grid is the upstream backend. The openai/ prefix on model selects LiteLLM's OpenAI-compatible client; api_base does the rest.
Prerequisites
Python 3.8+ and
uv add "litellm[proxy]"(the[proxy]extras cover both SDK and proxy).A Grid account at app.thegrid.ai with funded credits.
A consumption API key from your dashboard, exported as
THEGRID_API_KEY.
Pattern 1: LiteLLM SDK
import os
import litellm
response = litellm.completion(
model="openai/agent-prime",
api_base="https://api.thegrid.ai/v1",
api_key=os.environ["THEGRID_API_KEY"],
messages=[{"role": "user", "content": "Plan a three-step research task."}],
)
print(response.choices[0].message.content)The openai/ prefix is required. Streaming, tool calling, and structured outputs work the same way as any other OpenAI-compatible call (stream=True, tools=[...], response_format=...).
Pattern 2: LiteLLM Proxy
Run LiteLLM as a gateway. Any OpenAI-compatible client points at http://localhost:4000.
1. Install and set keys
2. Write config.yaml
Field-name gotchas: use api_base (not base_url), and os.environ/NAME (not ${NAME}) for env-var references.
The model_info block sets the token limits LiteLLM exposes through /model/info and its cost map. Downstream tools that read those values (Aider, SWE-agent, OpenHands, CrewAI) inherit them, so an accurate max_input_tokens here stops them from packing a request that overruns the window. Use 120,000 for input on Standard and Prime instruments, 922,000 on Max, and keep max_output_tokens below the instrument's context window. The Standard and Prime instruments carry a 128K context window; the Max instruments carry 1M. Get current per-instrument limits from Current instruments.
3. Start the proxy
4. Verify with curl
A 200 means LiteLLM accepted your master key, resolved grid/agent-prime to openai/agent-prime at api.thegrid.ai/v1, and returned a completion.
Point downstream tools at the proxy
Once the proxy is up, any OpenAI-compatible tool (Cline, Continue, your Python scripts) can use it as the inference backend:
Base URL:
http://localhost:4000(orhttp://localhost:4000/v1depending on the client)API key: your
LITELLM_MASTER_KEYModel name: any
model_namefrom yourmodel_list(e.g.,grid/code-prime)
Add or swap a backend once in config.yaml and every downstream tool picks up the change on proxy restart.
Stable aliases for multi-provider setups
If you want stable route names regardless of which backend fulfills them, alias them in model_list:
Your app calls model="default" and never touches a vendor name. Swap the backend in one place.
Troubleshooting
401 Unauthorized. Verify the key is a consumption key (not a trading key),
THEGRID_API_KEYis exported in the shell that started LiteLLM, andapi_baseis exactlyhttps://api.thegrid.ai/v1with no trailing slash. Test the key withcurl https://api.thegrid.ai/v1/chat/completions -H "Authorization: Bearer $THEGRID_API_KEY" -d '...'.402 Payment Required. Credits are empty. Top up at app.thegrid.ai. LiteLLM retries up to
num_retriesthen falls back if configured, but a 402 won't clear until you add funds."model not found" downstream. The
modelyour client sends must match amodel_nameinmodel_listexactly.grid/code-primeis not the same asgrid-code-prime.Cost tracking is approximate. LiteLLM tracks cost from a static pricing table. The Grid is a market with live pricing; LiteLLM's numbers are a rough guide. Source of truth is your spend in the app dashboard.
Last updated
Was this helpful?