Skip to content

LiteLLM

Route LiteLLM client calls and proxy models through AnyRouter as a custom OpenAI-compatible provider.

LiteLLM calls 100+ LLMs in the OpenAI format. Point it at AnyRouter as a custom OpenAI-compatible provider to reach the whole catalog from either the Python client or the LiteLLM Proxy.

Before you start

  • LiteLLM installed (pip install litellm), or a running LiteLLM Proxy.
  • An AnyRouter API key (prefix sk-ar-). Create one in the dashboard.

Set it up

Prefix the model with openai/ so LiteLLM uses its OpenAI-compatible path, set api_base to https://anyrouter.dev/api/v1, and pass your key. Choose the client or the proxy below.

pip install litellm
import litellm

response = litellm.completion(
    model="openai/google/gemini-3.5-flash",  # prefix with openai/
    api_base="https://anyrouter.dev/api/v1",
    api_key="your-anyrouter-api-key",
    messages=[{"role": "user", "content": "Explain load balancing."}],
)

print(response.choices[0].message.content)
model_list:
  - model_name: anyrouter-gpt-4o
    litellm_params:
      model: openai/openai/gpt-4o
      api_base: https://anyrouter.dev/api/v1
      api_key: os.environ/ANYROUTER_API_KEY
  - model_name: anyrouter-gemini
    litellm_params:
      model: openai/google/gemini-3.5-flash
      api_base: https://anyrouter.dev/api/v1
      api_key: os.environ/ANYROUTER_API_KEY

The openai/ prefix selects LiteLLM's OpenAI-compatible transport; the second segment (for example google/gemini-3.5-flash) is the AnyRouter model id. That is why proxy entries read openai/openai/gpt-4o.

Verify

Run the Python snippet, or start your proxy and call one of the model_name entries. A model reply confirms LiteLLM is routing through AnyRouter. Export your key first if you reference it from the environment:

export ANYROUTER_API_KEY="sk-ar-your-key-here"

Troubleshooting

401 Unauthorized

Confirm api_key (or ANYROUTER_API_KEY) holds a key that starts with sk-ar-. Manage keys in the dashboard.

404 model not found

The segment after the openai/ prefix must be a full AnyRouter provider/model id. Browse valid ids in the catalog.