Contact
Skip to the page text

Documentation / Guides / Integrations

LiteLLM

LiteLLM reads the platform as an OpenAI-compatible provider. Its proxy, or its Python SDK, sends requests to the platform's inference API with an API gateway key, the same way as every other API client (see API Overview). LiteLLM runs on your side; it must reach the platform's inference API, by default on port 443.

No setting is needed in the platform. You need three values from it: a key, the address, and the model names.

1. Create an API gateway key for LiteLLM

Open the APIs page. Under API Gateway Keys, choose Add key.

  • Name: litellm, or the name of your LiteLLM instance. Give each LiteLLM instance a key of its own.
  • The platform makes the key and shows it one time. Copy it then. It starts with onprem-gw-.

The Usage page counts requests and tokens for each API gateway key, so a key of its own shows what LiteLLM used. The platform sees LiteLLM as one client: which of LiteLLM's own users or virtual keys sent a request is in LiteLLM's records, not in the platform's.

When the key is revoked, LiteLLM's requests are refused in about one second.

2. Get the address and the model names

Both are on the APIs page.

  • The address: the URL in the API Endpoints table, for example https://10.0.4.10. LiteLLM needs it with /v1 at the end: https://10.0.4.10/v1. An IP address works; no DNS name is needed.
  • The model names: the API Paths table shows each deployed model with a Copy model name button. GET /v1/models answers the same names (see List Models).

3. Let LiteLLM trust the certificate

The inference API answers over HTTPS only, with a certificate from the control plane's own root CA. LiteLLM does not know that root CA, so it refuses the connection until you give it the certificate.

  1. Open Configuration → Security → Certificates (in your control plane) and choose Download Root CA. The file is onprem-ai-root-ca.crt. Check its fingerprint as Trusting the control plane in your browser says.
  2. Put the file where LiteLLM can read it. For LiteLLM in a container, mount it into the container.
  3. Name the file in LiteLLM's config.yaml (ssl_verify, see step 4), or in the environment variable SSL_CERT_FILE.

The file you name is then the complete list of certificate authorities that LiteLLM trusts. When the same LiteLLM also calls providers on the internet, give it one file that holds the public certificate authorities and the root CA:

cat "$(python -m certifi)" onprem-ai-root-ca.crt > litellm-ca-bundle.pem

Run the command with the Python that runs LiteLLM, and name litellm-ca-bundle.pem instead.

You can skip this step only when LiteLLM trusts the certificate already: the platform presents a certificate from your company's or a public certificate authority that LiteLLM's machine or container trusts. Do not set ssl_verify: false: the key travels in every request.

4. Add the models to LiteLLM

In the LiteLLM proxy's config.yaml, add one entry for each model:

model_list:
  - model_name: my-model-id                 # the name LiteLLM's clients send
    litellm_params:
      model: openai/my-model-id             # openai/ + the model name from the APIs page
      api_base: https://10.0.4.10/v1        # the address from the APIs page + /v1
      api_key: os.environ/ONPREM_AI_API_KEY # the API gateway key, from the environment
      timeout: 600                          # seconds; see "Long answers" below

litellm_settings:
  ssl_verify: /etc/litellm/onprem-ai-root-ca.crt
SettingValue
model_nameYour choice. LiteLLM's clients send this name.
litellm_params.modelopenai/ and then the model name, exactly as the APIs page shows it. openai/ tells LiteLLM to speak the OpenAI API; it does not send requests to OpenAI.
litellm_params.api_baseThe address with /v1 at the end, and nothing after it. LiteLLM adds /chat/completions and the other paths itself.
litellm_params.api_keyThe API gateway key. os.environ/ONPREM_AI_API_KEY reads it from the environment variable ONPREM_AI_API_KEY, so the key is not in the file.
litellm_settings.ssl_verifyThe path of the certificate file from step 3, as LiteLLM sees it.

Set the key in LiteLLM's environment and start the proxy:

export ONPREM_AI_API_KEY=onprem-gw-...
litellm --config config.yaml

A model that you deploy later needs an entry of its own. A model that you undeploy answers 404 until you remove its entry.

5. Send a test request

Send the request to LiteLLM, not to the platform. LiteLLM's proxy listens on port 4000 by default:

curl http://localhost:4000/v1/chat/completions \
  -H "Authorization: Bearer <your LiteLLM key>" \
  -H "Content-Type: application/json" \
  -d '{"model": "my-model-id", "max_tokens": 64, "messages": [{"role": "user", "content": "Hello"}]}'

The answer is a chat completion. On the platform, the Usage page shows the request under the key from step 1.

Set max_tokens on every request, as small as the use needs: a smaller value lets the model serve more requests at the same time (see How the Gateway Refuses Work).

The Python SDK, without the proxy

The same four values go into the call:

import litellm

response = litellm.completion(
    model="openai/my-model-id",
    api_base="https://10.0.4.10/v1",
    api_key="onprem-gw-...",
    ssl_verify="onprem-ai-root-ca.crt",
    max_tokens=64,
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

What works through LiteLLM

LiteLLM routeOn the platform
/chat/completions, streamed or notWorks for every model with the OpenAI API. A streamed answer ends with the exact token counts, also when the client did not ask for them (see Chat Completions).
/embeddings, /completions, /rerankWorks when the deployed model serves that operation. The platform forwards the request to the model; the model decides.
/v1/messages (Anthropic format)Add use_chat_completions_url_for_anthropic_messages: true under litellm_settings. Without it, LiteLLM sends these requests to /v1/responses, which answers only when the deployed model serves it.
/audio/transcriptions and other file uploadsDoes not work through an openai/ entry. The platform reads the model name from a JSON body under /v1, and an upload has none. Call the model's own path on the platform directly (see Passthrough APIs).

A model that answers only an API of its own (OCR and others) is not in /v1/models and has no openai/ entry in LiteLLM. Call it directly too.

Long answers

A large language model can take minutes to answer, and the platform lets an answer take up to 10 minutes to start (see Long Requests and Timeouts).

  • Keep timeout: 600 in the model's litellm_params. With a shorter timeout, LiteLLM gives up on a request that the platform would still answer, and the work done so far is lost.
  • Use streaming for long answers. The platform starts a streamed answer within 2 seconds and sends a keepalive line every 15 seconds, so a proxy or load balancer between LiteLLM and the platform does not close the connection.
  • A proxy or load balancer between LiteLLM and the platform must allow the same times. The same document says what to set.

When the platform has no room for a request, it answers 503, with a Retry-After header when a retry after that time can help. Keep LiteLLM's retries few (num_retries), and do not set a fallback that sends the same request to the same model again at once: retries without a pause make an overload longer.

When LiteLLM shows an error

LiteLLM passes the platform's reason on in its own error text. The code in that text names the cause (see API Overview, "Error envelope").

LiteLLM showsCauseNext step
CERTIFICATE_VERIFY_FAILED, or a connection error that names SSLLiteLLM does not trust the platform's certificate, or the address is not one the certificate names.Do step 3 again and check the path in ssl_verify. For an address the machine does not have itself (a DNS name, a load balancer), see "Adding a DNS name" in Trusting the control plane in your browser.
A connection error or a timeout before any answerLiteLLM cannot reach the inference API.From LiteLLM's machine, run curl --cacert onprem-ai-root-ca.crt https://<address>/healthz. The answer is {"status":"ok"}. If not, check the address, the port (443 by default) and the firewall between the two.
401, code missing_api_keyLiteLLM sent no key: the environment variable is not set where LiteLLM runs.Set ONPREM_AI_API_KEY in LiteLLM's environment and restart LiteLLM.
401, code invalid_api_key or revoked_api_keyThe key is wrong, or it was revoked.Create a new key on the APIs page and give it to LiteLLM.
404, code no_such_routeNo deployed model has the name in litellm_params.model, or api_base does not end in /v1.Copy the model name from the APIs page again, keep the openai/ in front of it, and check api_base.
400, the text names a JSON request bodyLiteLLM sent a file upload to a path under /v1.Call the model's own path directly (see Passthrough APIs).
413, code request_too_largeThe request is larger than 16 MiB.Send a smaller request, for example smaller or fewer images.
503, code model_not_availableThe model is deployed, but no replica of it can answer now: it is starting, restarting, or its inference node is not connected.Open the Status page for the model's state, and retry when it answers again.
503, code auth_unavailableThe platform cannot check keys at the moment.Retry in a minute. If it stays, see Platform Containers.
503 with another code and Retry-AfterThe model has no room for the request now.Retry after the time the header names. If it happens often, see How the Gateway Refuses Work.

Found a mistake, or is something missing? Suggest an improvement to this page on GitHub.

Platform release 5.10.4, . Source of this page at v5.10.4. This page as Markdown.