A dspy.LM that will not reach the gateway usually fails on a point that surprises people the first time: DSPy reads the model string in two parts, a provider hint before the slash and the catalog id after it, and mixing those two up is the most common DSPy-specific miss. This page is the troubleshooting companion to the DSPy setup guide, which has the working call; here you start from an error and work back to its cause. The base is https://api.uplinkswitch.com/v1.
Raised before the request, or after it?
The first split is whether anything reached the gateway. An exception raised while the lm object is built, or before a single request goes out, comes from DSPy's provider layer: the string named no provider it knows, or a required argument is missing. Every gateway refusal instead arrives with an HTTP status and a code in the body. Knowing which kind you have tells you whether to fix the Python call or the values passed into it.
The provider hint is not the model id
For an OpenAI-compatible endpoint, DSPy wants the string as openai/<id>. The openai half chooses the client and the request format; the half after the slash is what the gateway reads as the model. Two mistakes produce most of the failures. Dropping the prefix leaves DSPy to work out a provider from a bare name it does not know, which can fail before any request leaves. Doubling it, as in openai/openai/gpt-6.1-sol, leaves openai/gpt-6.1-sol as the id, which matches no catalog entry and returns a 404 with the code model_not_found.
import os
import dspy
lm = dspy.LM(
"openai/gpt-6.1-sol",
api_base="https://api.uplinkswitch.com/v1",
api_key=os.environ["UPLINKSWITCH_API_KEY"],
)
dspy.configure(lm=lm)On the 2026-11-23 catalog gpt-6.1-sol read ok.
api_base stops at /v1
api_base takes the gateway root and nothing after it. The client under DSPy appends the chat route itself, so a value that already ends in /chat/completions builds a doubled path, and the gateway answers it with a 404 whose code is route_not_found. That gives two 404 codes with two different fixes: route_not_found is the api_base value, while model_not_found is the id after the prefix.
A 401 is the api_key argument
A 401 with invalid_api_key is the api_key value. When the message reads No API key was sent., the argument resolved to nothing, most often because the variable was never exported into the process running the program, such as a notebook kernel started before you set it. When it reads The API key is not valid., a value arrived but is mistyped, revoked, or belongs to another vendor. A key whose allowlist omits the model still authenticates and comes back 403 scope_denied instead.
Check the id without spending a request
The catalog needs no key and makes no model call, so it is the cheap way to confirm the id after the prefix:
curl https://api.uplinkswitch.com/v1/catalogCopy the id exactly, and look at its availability. An id flagged degraded is a catalog state, not a fault in your DSPy wiring; swap the part after openai/ for a sibling that reads ok, such as claude-sonnet-5-5, which showed ok on the same snapshot.
Only the second model fails
A program can bind another dspy.LM to part of its run, with a different id on the same api_base and key. If only that second model fails, the first one has already proved the endpoint and the key, so the fault is the second id: read it on the catalog before changing anything else. The LiteLLM guide covers the adapter that older DSPy releases ran on, if your traceback comes from that layer.