DSPy
DSPy replaces hand-written prompts with declarative modules
and optimisers. Configure it once with dspy.LM and every module in your
program uses Hyphen.
Code
Setup guide: this config comes from DSPy's official documentation and has not been run end to end against the gateway. Corrections to support@hyphen-solution.com.
The model
Code
Two naming details, both easy to get wrong:
- The
openai/prefix is required. DSPy routes through LiteLLM, and the prefix is what tells it to treat this as a generic OpenAI-shaped endpoint. DSPy's own docs say to add it for any OpenAI-compatible provider. It is stripped before the request, so Hyphen receivesminimax-m3. - It is
api_base, notbase_url. That is LiteLLM's name.api_baseandapi_keyare not named parameters ondspy.LM; they ride through**kwargsinto LiteLLM, which is by design.
model_type="chat" is the default and can be omitted. Passing it explicitly is
cheap insurance.
Predict and ChainOfThought
Code
ChainOfThought injects a reasoning field before your declared outputs. Note
that this is DSPy's own prompted reasoning, which is separate from the
model's internal reasoning. Both consume tokens from the same max_tokens
budget, which is why 4000 is the floor here.
A typed signature
Code
DSPy builds structured output by prompting and parsing, not by
response_format, so it works on the M-series without any special
configuration.
A module with tools
Code
Keep max_iters bounded. A ReAct loop that will not converge is the fastest
way to spend a monthly cap.
Two models in one program
Use the cheap fast model for bulk classification and the flagship where quality matters.
Code
Optimisers and your budget
DSPy's optimisers (MIPROv2, BootstrapFewShot and friends) work by running
your program many times over a training set. That is dozens to hundreds of
requests per compile.
Do the optimisation runs on minimax-m2.5, check your remaining budget in the
console first, and keep the trainset small
while you are iterating. The hard cap means a runaway compile returns 429
rather than an invoice, but a spent cap still stops your day.
DSPy caches by default (cache=True on dspy.LM), so repeated identical calls
during development cost nothing.
Gotchas
openai/prefix required. Without it LiteLLM cannot route the call.api_base, notbase_url.max_tokensof 4000. Prompted reasoning plus internal reasoning share the budget. See Choosing a model.- No embedding models on the gateway, so DSPy retrievers need an embedder from elsewhere.
429means the monthly budget is spent. Optimisers reach it fast. See Handling the 429 cap.
Related
- DSPy language models
- dspy.LM reference
- Choosing a model: which model for compile vs run.