LiteLLM with any OpenAI-compatible model server

Connect llama.cpp, LM Studio and other OpenAI-compatible servers to a self-hosted LiteLLM gateway using the openai/ prefix, correct base URLs and governed keys, and know when a dedicated route fits better.

On this page

How LiteLLM reaches a model behind an OpenAI-compatible server

A team running private models on llama.cpp or LM Studio usually wants those models governed next to cloud providers, with one gateway handling keys, budgets and logs. LiteLLM supports this through a generic route: you address the model with the openai/ prefix, and LiteLLM calls it with the upstream OpenAI client. This is a generic method, not a connector built for a specific server, so it works with any server that speaks the OpenAI request format. Treat it as the fallback you reach for when no dedicated route fits, and check the route list in the LiteLLM docs for OpenAI-compatible endpoints before you commit to it.

Two details cause most first-day failures. First, the OpenAI client requires an API key, so LiteLLM will not send a request without one. Your server may not check the key at all, in which case any placeholder value works, but it must be present in the model configuration. If you enable API key authentication on llama-server through --api-key or an API key file, the placeholder must match a real key that the server accepts. Second, set api_base to the server's root base URL, the way the server documents it for OpenAI clients. Do not append endpoint paths such as /v1/embedding, because LiteLLM builds the request path itself. Confirm the exact base URL your server version expects by sending one test request directly to the server before you add it to LiteLLM.

Plan the route choice before you write the config. The generic openai/ route gives you chat completions and the endpoints the server exposes, but it does not encode server-specific behavior, so pricing, parameter handling and endpoint support depend on what your server actually returns. Confirm which endpoints your server exposes (llama-server documents chat completions, responses and embeddings routes) and test each one you plan to route. If the model is served by vLLM, a dedicated hosted_vllm/ route is usually the better fit, covered in the sibling section on self-hosted vLLM models.

What you need before connecting a local model server

Before LiteLLM can route traffic to a llama.cpp, LM Studio or other OpenAI-compatible server, the gateway, its data stores and the model server need to be ready. The cards below cover the gateway state, the server version, network path and server-side authentication that connect them.

PostgreSQL for virtual keys

Virtual keys, per-key budgets and spend tracking all need a PostgreSQL database behind the proxy. Without it, the local model route can still be configured, but the controls that make it governable are not available. Confirm that the database is provisioned, backed up and reachable from every proxy instance, and that the connection string is stored in a secret manager rather than in the configuration file.

Virtual keys docs

Redis for multiple proxy instances

Once more than one proxy instance serves the same model server, rate limits, router state and cache must be shared. Redis 7.0 or newer covers that role. Confirm whether the planned deployment runs one instance or several, because a single instance can start without Redis while a horizontally scaled gateway cannot. Ask the platform team where Redis will run and who owns its availability.

Model server version and build

Pin the llama.cpp build or the LM Studio, vLLM or other server release you will test against, and record it in the gateway change record. The latest llama.cpp build in the supplied release history is b11717, published October 18, 2026. Confirm that the build supports the chat, responses or embeddings routes your callers use, and that the GGUF model files you serve are validated on that build before production traffic reaches them.

llama.cpp releases

Network path from LiteLLM

The proxy pods or hosts must reach the model server's address and port directly, through any firewall, security group or Kubernetes network policy in between. Confirm the base URL the gateway will use, whether the server is on the same cluster, another subnet or a GPU host outside the cluster, and that DNS resolves from inside the proxy container. Test the path from the proxy environment itself, since a route that works from a laptop may not work from the pod.

API key and TLS on the server

llama-server can require an API key through the --api-key option or an API key file, and it can serve TLS with PEM certificate and key files. Decide which of these the server will use before configuring LiteLLM, because the gateway must send the matching key and trust the certificate chain. Confirm who issues and rotates the server key, where it is stored, and whether traffic between the gateway and the server crosses a network segment that needs encryption.

llama-server README

Metrics endpoint decision

llama-server can expose a Prometheus-compatible metrics endpoint when started with --metrics. Decide before go-live whether the platform team will scrape it, since that endpoint may reveal load and model details to anyone who can reach the port. Confirm the scrape path, the network allowed to reach it, and whether it sits behind the same authentication as the inference routes.

Configuring the openai/ route step by step

This sequence takes a llama.cpp, LM Studio or other OpenAI-compatible server from a running model to a request that reaches it through a LiteLLM virtual key. Each step ends with a check so you know the layer below works before you add the next one.

  1. Start the model server with a model loaded

    The model server operator starts llama-server, LM Studio's server or another OpenAI-compatible server with a model loaded and an API key set. For llama-server, the key comes from the --api-key option or an API key file. Keep the server on a network address the LiteLLM proxy can reach, and use TLS if the traffic crosses a network boundary. The step is done when the server reports that the model is loaded and is listening on its port.

  2. Confirm the chat route answers with curl

    Before involving LiteLLM, send one chat completion request directly to the server with curl, using the server's base URL plus the chat completions path and the same API key. Use the model name the server expects. Request a short completion so the response is quick to read. The step is done when you get a JSON response with a choices array and generated text. If you get an authentication error, fix the key here, because LiteLLM will fail the same way.

  3. Add the model entry with the openai prefix

    The LiteLLM administrator adds a model entry to the proxy configuration file. Set model_name to the alias your callers will use, and set the litellm_params model value to openai/ followed by the model name the server reports. The openai/ prefix tells LiteLLM to use its upstream OpenAI client, which is why the server is treated as a generic OpenAI endpoint. The step is done when the configuration file parses without errors and the entry lists the alias you intend to publish.

  4. Set api_base to the server root

    In the same entry, set api_base to the server root, for example the host and port without a trailing path. LiteLLM adds the OpenAI route paths itself, so adding /v1 or an embeddings path to the base URL usually produces wrong request URLs. Confirm the value against the curl test from the previous step, adjusted for the path the server exposes. The step is done when the base URL matches the host you tested and the proxy can resolve and reach it from its own network location.

  5. Set a placeholder key from a secret manager

    Set api_key in the entry to a value that comes from your secret manager or environment, not a literal in the file. The OpenAI client requires a key, so if the model server has no authentication, use a placeholder string that the server ignores. If the server does check keys, store the real key in the secret manager and reference it. Keep the configuration file in version control only with references, never with the value itself. The step is done when the file contains no plain key and the proxy starts with the reference resolved.

  6. Restart or reload the proxy

    Restart the LiteLLM proxy, or reload its configuration if your deployment supports that, so the new model entry is loaded. Watch the startup log for the model alias and for any warnings about the entry. Then query the proxy's model list with an authorized request to confirm the alias appears. The step is done when the alias is listed and the startup log shows no errors for that entry. Check the exact reload behavior for your deployment method and LiteLLM release, since it varies.

  7. Send a test request through a virtual key

    Create a virtual key restricted to the new model alias, then send a chat completion to the proxy using that key and the alias. Do not test with the master key, because the test should prove the access path your callers will use. Check that the response comes from the model server and that the request appears in the proxy's spend and request logs. The step is done when the request succeeds, the logs record the alias and key, and a request with the key for a different model is refused.

When openai/ fits and when hosted_vllm fits better

The openai/ prefix tells LiteLLM to treat the upstream as a plain OpenAI-compatible API and send requests with the upstream OpenAI client. This is the default starting point for llama.cpp's llama-server, LM Studio and most other servers that accept the OpenAI request format. It needs only a base URL, a model name and an API key value, even if the server ignores that key.

  • Broad fit: Works with any server that implements the chat completions routes your callers use, so one configuration pattern covers several local servers.
  • Endpoint coverage: llama-server documents chat completions, responses and embeddings routes. Confirm which of these your callers need and which your server build exposes.
  • Base URL rules: Enter the base URL that ends at the version prefix, not a full path such as an embeddings route. LiteLLM adds the endpoint path itself.
  • Cost tracking: Local models have no provider price list, so spend figures depend on the cost settings you define for each model entry. Set them deliberately or budgets will not reflect real usage.
  • Limits: Provider-specific behavior is not tailored for each server, so unusual parameters may pass through unchanged or fail on the server side.

Before relying on this route, confirm current behavior in the LiteLLM OpenAI-compatible docs and test each endpoint your applications call.

Mapping model names, keys and base URLs between the two systems

This table compares each identifier LiteLLM uses with the matching value on the model server, showing who sets it and where it lives. Read it row by row when you add a server, because a mismatch in any one value usually produces a not-found or authentication error that looks like a server fault.

ValueWhat it is on the LiteLLM sideWhere it is set and who owns it
model_name aliasThe name callers send in their requests, such as a team-facing label that you chooseSet in the proxy config file under model_list; owned by the platform team and reviewed when callers change
Upstream model idThe name the server expects, which for llama.cpp is often the GGUF alias or a fixed id, and for LM Studio is the loaded model identifierRead from the server's model list endpoint or its UI; owned by whoever loads or swaps models on the server
openai/ prefixTells LiteLLM to use the upstream OpenAI client and send the text after the prefix as the model nameWritten in litellm_params as the model value; owned by the platform team, and it must match the server's expected format
api_baseThe server's base URL ending in the version path, without endpoint suffixes such as /embeddingsStored in the proxy config or a secret reference; owned by the platform team and changed when the server moves
Placeholder keyA dummy value that satisfies the OpenAI client when the server runs without authenticationStored in a secret manager or environment variable; owned by the platform team, and it is not a real credential
Real server keyThe key the server checks when started with an API key option, which LiteLLM must send upstreamStored in the secret manager and referenced from the config; owned by the team that runs the server
Virtual key scopeThe list of model_name aliases a virtual key may call, enforced by the gateway before any request reaches the serverSet when the key is issued in the admin UI or API; owned by the gateway administrator and approved by the team lead
Budget and rate limitsPer-key or per-team spend and TPM or RPM caps applied to the aliases the key can reachSet on the key or team record; owned by the gateway administrator, with the finance or team owner approving the amounts

Why fake API keys still need careful handling

A local model server with no real authentication still needs a key value in LiteLLM. The upstream OpenAI client expects an API key on every call, so a placeholder is the normal way to satisfy it. That placeholder is harmless only while the server ignores it. Once someone configures the server to check keys, or the same config file is copied into a shared environment, the placeholder becomes a credential like any other, and it should be handled as one.

The main risk is that a placeholder looks too much like a real credential. An auditor or reviewer who reads a config file and sees a value beginning with sk- followed by a long random string may assume a live provider key is stored in plain text. Use an obviously fake value, such as a readable label, and document in the deployment record that it is a placeholder for a server with no authentication. Do not reuse a value that matches the format of a real provider key, and do not copy one from a provider console.

When llama-server is started with --api-key or an API key file, the value LiteLLM sends must match exactly, or every request fails authentication. Treat the two settings as one change: rotate them together, and record which gateway and which server share each value. Store the key in your secret manager rather than in config.yaml, inject it into the LiteLLM container at runtime, and confirm with your security team how rotation and access to the secret will be audited. Check the llama-server README for the current flag behavior before you rely on it.

Securing the link between LiteLLM and a private model server

LiteLLM sends prompts and receives responses from your model server on every call, so the connection between them is part of your data path. The controls below cover how the server authenticates callers, how traffic is encrypted, where the server can be reached from, and how the gateway's own secrets and virtual keys are limited. Confirm each one in your environment before the gateway carries production traffic.

Require an API key on llama-server

Start llama-server with --api-key or point it at an API key file so requests without a valid key are rejected. LiteLLM sends the key through the OpenAI client it uses for the openai/ prefix, so the key must be set in the LiteLLM model entry and kept out of the config file in plain text. Check that a direct request without the key fails, and that rotating the key on the server and in LiteLLM is a documented step. Confirm the key reaches the server on every route LiteLLM uses.

llama-server README

Encrypt the gateway-to-server hop

llama-server can terminate TLS with PEM certificate and key files, so prompts and API keys do not cross the network in clear text. Decide whether the certificate is issued by your internal CA and whether LiteLLM must trust that CA through its runtime certificate bundle. Test the connection with a certificate check enabled, not disabled, and record the certificate expiry date so renewal is planned. Plain HTTP is acceptable only on a single host or a segment you already isolate.

llama-server README

Limit which network can reach the server

Bind llama-server to a private interface and allow inbound connections only from the LiteLLM proxy hosts or pods, using host firewall rules or Kubernetes network policies. Developers and chat clients should reach models only through the gateway, so the model server never becomes a second, ungoverned entry point. Confirm the base URL in LiteLLM resolves to that private path and that the server refuses connections from any other address. A model server reachable from user networks bypasses keys, budgets and logs.

Store the LiteLLM master key in a secret manager

The LITELLM_MASTER_KEY must start with sk- and grants administrative control of the proxy, including key creation and budgets. Keep it in a secret manager that your platform team already audits, not in a values file or container image, and inject it at runtime. Also confirm that the API key for llama-server is stored the same way, and set a rotation owner for both. Treat the master key as the highest-privilege credential in the gateway.

LiteLLM production guide

Restrict virtual keys to approved models

A virtual key can be limited to specific models, so a key issued for a team can call the private model server while other keys cannot. This matters because the model server key is shared behind the gateway, and the gateway is the only place that decides who reaches it. Test that a key scoped to one model is refused on the private model name, and review scopes when teams or models change. Confirm that no default or unscoped key can reach the private model.

LiteLLM virtual keys docs

Enable metrics only where they are needed

llama-server offers an optional Prometheus-compatible metrics endpoint, enabled with --metrics. The endpoint can reveal load, model names and timing data, so leave it off unless your monitoring stack scrapes it from a restricted address. If you enable it, place it behind the same network rules as the API and confirm which scrape job owns it. Decide who may read metrics before turning the flag on.

How a request travels from a caller to a private model

The request starts at a caller holding a LiteLLM virtual key, which the LiteLLM proxy checks against budgets, rate limits and the models that key may use. The router then selects a deployment and sends the call through the openai/ route to the llama-server or LM Studio endpoint in the model host network. The trust boundary sits between the gateway network and the model host, so check that only the gateway can reach the model port, that the upstream credential is held by the gateway, and that the model host has its own authentication enabled.

Request path from a virtual key through the LiteLLM proxy to a private OpenAI-compatible model server.

Why calls to a local model server fail after setup

This table lists the failures teams hit most often when LiteLLM calls a llama.cpp, LM Studio or other OpenAI-compatible server. Each row gives the likely cause and the fix, so you can check the base URL, key, model id, certificates, networking, timeouts and virtual key permissions in order.

FailureLikely causeFix
Requests return 404 or wrong routeThe base URL includes a path such as /v1/chat/completions or /v1/embedding, so LiteLLM appends its own path a second timeSet the base URL to the server root that LiteLLM expects, without endpoint paths, and confirm the route against the LiteLLM OpenAI-compatible docs
Authentication error from the upstream serverThe server was started with --api-key but LiteLLM sends no key or a different one, or the openai/ route requires a key the server ignoresPass the server's configured key through api_key in the model entry, or set a placeholder value when the server has no key check
Model not foundThe model field does not match the name the server loaded, often a GGUF file name or an alias set at startupList the models the server reports, copy the id exactly, and use the openai/ prefix followed by that id
TLS or certificate errorsThe server uses a private or self-signed PEM certificate that the LiteLLM container does not trustMount the CA bundle into the LiteLLM container and point the client at it, or confirm the certificate chain with your platform team before disabling verification
Connection refused or timeout from Kubernetes podsThe host address is a loopback or laptop address that pods cannot reach, or a network policy blocks the portUse a routable service address for the server, check that the pod network can reach the port, and confirm network policies with your cluster team
Long generations cut off or stallStreaming is not passed through correctly, or the client or proxy timeout is shorter than the generation time on local hardwareTest with streaming on and off, raise the timeout for that model entry, and align any reverse proxy or load balancer timeouts
Virtual key gets a permission error on the aliasThe key is restricted to specific models and does not include the model alias that routes to the local serverAdd the alias to the key's allowed models, or create a team key for the alias, then retest with that key

Questions teams ask before connecting a local model server

What drives the cost of connecting a local model server to LiteLLM?

The largest cost components are the hardware that hosts the model, the configuration work in LiteLLM, and the testing and governance setup around it. Hardware is usually a one-time purchase or a recurring infrastructure charge, depending on whether you run on owned servers or rented capacity. Configuration effort is mostly one-time. Testing, key policy, budgets and logging are one-time to set up but need upkeep as models and users change. Ask any partner for a quote that separates these components, names who pays for each, and states which items recur. Model host sizing depends on the model you choose, the number of concurrent users and the context lengths your teams send, so confirm those inputs before comparing quotes.

How long does a basic connection take?

A basic connection of one OpenAI-compatible server to a LiteLLM gateway that already runs is mostly a configuration and test task, so its duration depends on the environment more than on the server software. Teams that already run the gateway, have the model server reachable on a known address, and have an agreed key owner can finish the first connection and smoke tests quickly. Duration grows when the model server must be installed, when network paths cross firewalls or segments, when TLS and API key handling need review, or when budgets, access rules and logging must be designed before callers are switched over. Ask for a written timeline tied to the environment you describe, not a generic estimate.

What does our team need to supply before the work starts?

Several inputs must be ready before anyone changes the gateway configuration:

  • Access to the machine or cluster that runs the model server, with permission to install or update it.
  • The model choice, including its file format and licence terms, and who approved it for internal use.
  • Network paths from the LiteLLM gateway to the model server, including any firewall rules and the address and port the server listens on.
  • A named owner for each API key the gateway uses to call the server, and for who may change it.
  • A test set of prompts or requests that reflect real use, so results can be checked after the connection is made.

Missing any of these usually adds rounds of back and forth rather than extra build work.

Can our internal engineers connect a local model server themselves?

Yes, a team that already operates LiteLLM and one model server can usually connect a second server by following the configuration rules for OpenAI-compatible endpoints. The main skills are reading the base URL rules, choosing the correct provider prefix, handling the placeholder key that such servers often need, and testing responses. The work becomes harder when the server must be secured with an API key, TLS and metrics, when several models sit behind one route, or when budgets and per-team access must match a governance policy. Internal staff who own the platform, security and compliance review are the right people to decide these points, even when a partner helps with the build.

When is outside help worth paying for?

Outside help is worth considering when the connection must pass a security or compliance review soon, when several model servers and teams must share one gateway, or when your staff have no spare time to test and document the result. A partner can scope the work in writing, build and test the connection, and hand over runbooks and configuration your team can operate. Ask for the scope, deliverables, testing approach and handover steps in a written proposal. DeployOpen implements, configures, tests and documents self-hosted open-source platforms inside the client's own infrastructure, and most engagements are fixed-scope, with the scope agreed in writing before work starts.

Which risks should we check before exposing a model server to the gateway?

The main risks are unauthenticated access to the model server, data sent over unencrypted connections, and loss of control over which callers can reach which models. Before connecting, confirm whether the server can require an API key, whether it can serve TLS with your own certificate files, and whether its metrics endpoint is enabled and reachable only from monitoring systems. The gateway should be the only caller that holds the server's key, and access should be limited by network rules so the server is not reachable from the open internet. Confirm each of these settings against the documentation for the exact server version you run.

Does a local model server need a licence review?

Yes. The server software and the model weights carry separate licence terms, and both need review before internal use. The server project and LiteLLM are open source under their own licences, but a model's weights may restrict commercial use, redistribution or certain user groups. Ask your legal or compliance team to review the licence of each model you plan to serve, record the approval, and keep the record with the gateway configuration. The review is a one-time task for each model, but it must be repeated when a model changes version or source.

How DeployOpen scopes and delivers this connection

DeployOpen works from a written scope before any connection is built. DeployOpen is a Chainscore Labs company. It plans, deploys, integrates, hardens and documents self-hosted open-source platforms inside the client's own infrastructure, including their cloud accounts, data centers and air-gapped networks. For an OpenAI-compatible server behind LiteLLM, the scope usually names each upstream server, its base URL and network path, the model names exposed through the model_list entries, the key handling for each upstream, the virtual key and budget design on the gateway, and the logging and retention settings the client's security team needs to review. Most engagements are fixed-scope, so these items, the deliverables and the timeline are agreed in writing before work starts.

A quote follows from that written scope, not from a list price. DeployOpen does not publish a price list. The factors that move the quote for this kind of connection are the number of upstream servers, whether each one needs its own route and authentication, whether the gateway already runs in production or is being built alongside this work, and how many teams and keys need to be set up. Ask for the quote to separate one-time work (configuration, testing, documentation, knowledge transfer) from any recurring support, and to state which items the client's own team will perform. Ask DeployOpen to confirm exactly which llama-server or LM Studio versions and which LiteLLM release line the scope covers.

Integration testing is part of delivery, and ongoing support is optional. Before handover, the connection is tested with real requests through the gateway: a successful call to each model name, a rejected call with an invalid or missing key, a check that a virtual key cannot reach models outside its allowed list, a check that spend is recorded against the right key and team, and a failover test if a fallback route is defined. The results are documented with the configuration. For clients who want continuous help, DeployOpen offers retainers for ongoing support, upgrades and continuous testing, which can cover upstream server updates and LiteLLM release changes after the initial work is complete.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.