Contents
To run DSPy on SolCard Inference, create dspy.LM("openai/solcard-inference-fast", api_base="https://api.solcardinference.ai/v1", api_key=...) with your sk-si- key. DSPy’s language models guide says that for “an OpenAI-compatible Chat Completions endpoint using bearer authentication, you can use an openai/ prefix” with an explicit API base and key. That’s the whole integration. Everything about DSPy below comes from its own docs; we haven’t run it ourselves.
What you need
- A SolCard Inference API key. Make one on the dashboard’s API keys page. Keys start with
sk-si-and are shown once. - Some balance or a plan. One prepaid USD balance pays for every key and model; see how billing works.
- DSPy on Python 3.10 or later. Its setup page installs it with
pip install dspyand says it “works in Python 3.10+ environments.” LiteLLM is an optional extra there, not a requirement.
pip install dspy
export SOLCARD_INFERENCE_KEY=sk-si-...
Configure the LM
One dspy.LM, set as the default with dspy.configure:
import os
import dspy
fast = dspy.LM(
"openai/solcard-inference-fast",
api_base="https://api.solcardinference.ai/v1",
api_key=os.environ["SOLCARD_INFERENCE_KEY"],
max_tokens=4096,
)
dspy.configure(lm=fast)
qa = dspy.Predict("question -> answer")
print(qa(question="What does a base URL ending in /v1 mean?").answer)
The model id after openai/ is our full name. The prefix tells DSPy which wire format to speak; solcard-inference-fast is what reaches us. The setup page’s own example puts /v1 at the end of api_base, which matches our base URL exactly.
Keep max_tokens at or under 32,768. That’s the most any of our models writes per request. Our Chat Completions reference accepts max_tokens as an alias for max_completion_tokens.
Switch models for one block with dspy.context. The guide says “You can change the default LM globally with dspy.configure or change it inside a block of code with dspy.context,” and that both are thread-safe:
large = dspy.LM(
"openai/solcard-inference-large",
api_base="https://api.solcardinference.ai/v1",
api_key=os.environ["SOLCARD_INFERENCE_KEY"],
max_tokens=16000,
)
with dspy.context(lm=large):
print(qa(question="Plan a migration from REST to gRPC.").answer)
solcard-inference-large always reasons, and per our reasoning guide reasoning tokens bill as output, so give it a higher max_tokens than Fast. Fast, Large or Base covers which one fits which module.
The cache DSPy keeps on your disk
We keep nothing you send, but DSPy keeps a copy of answers on your machine by default. The guide says “By default LMs in DSPy are cached.” The cache tutorial lists an in-memory cache and an on-disk cache, and says the disk one uses Python pickle. It also says cache keys leave out credentials such as the API key.
The disk cache lives in ~/.dspy_cache unless you move it. DSPy PR #10610, merged October 26, 2026, says the only location variable is DSPY_CACHEDIR, with that default, and that it has to be set “before import dspy since it is read at import time.”
If you’re working on client code or anything else that shouldn’t sit in a home directory, turn both caches off before you run anything:
dspy.configure_cache(
enable_disk_cache=False,
enable_memory_cache=False,
)
Or pass cache=False to one dspy.LM; the tutorial says that flag “still controls DSPy’s answer cache.” Keeps nothing covers our side of the path; this setting covers yours.
A cached answer also means a repeated call won’t ask again. That saves money while you iterate. When you want fresh samples, the guide says to “pass a unique rollout_id and set a non-zero temperature in your call,” and warns that a rollout_id with temperature=0 “will not affect the LM’s output.”
lm.history holds your prompts in memory too. The guide says “Every LM object maintains the history of its interactions,” with usage in each entry. It’s handy for debugging and gone when the process ends, unless you save it.
Split models for optimizers
MIPROv2 takes two models: one runs your program, one writes the instructions. The MIPROv2 reference lists prompt_model and task_model, and says the context it gathers “is provided to a prompt_model which writes high quality instruction candidates.” auto defaults to 'light'.
optimizer = dspy.MIPROv2(
metric=my_metric,
prompt_model=large,
task_model=fast,
auto="light",
)
optimized = optimizer.compile(dspy.ChainOfThought("question -> answer"), trainset=train)
The task model runs your program in every trial, so put the cheaper model there. The reference says the optimizer runs trials that score candidate prompts on minibatches and, now and then, on the full validation set. It gives no call count for a run, so here is a made-up one: 500 calls, each sending 2,000 tokens and getting 300 back. That’s about $1.63 on Fast and about $4.69 on Large plus its reasoning, before any cached-input discount. Repeated few-shot prefixes may bill at the cached input rate, a tenth of the input price.
Watch num_threads against your rate limit. MIPROv2 takes a num_threads argument. On a plan, the per-minute limit is 120 requests on Starter, 300 on Pro and 600 on Max; going past that with too many threads buys you 429s, not speed.
Check it works
Rule out DSPy first: if this curl fails, the problem is the key or the URL.
curl https://api.solcardinference.ai/v1/models \
-H "Authorization: Bearer $SOLCARD_INFERENCE_KEY"
The list should name solcard-inference-fast, -large and -base. Then run the first example with cache=False, so a cached answer can’t hide a broken key. Codes from our errors page:
- 401
invalid_api_key: the key is missing, revoked or unknown. - 400
model_not_found: the id afteropenai/must be the fullsolcard-inference-...name. - 400
unsupported_content: an image or file reached the model; ours take text only. - 402
insufficient_balance: top up, then retry. - 429
rate_limitedorplan_limit_reached: too many requests a minute, or the plan’s weekly limit is used up.
FAQ
Is there a SolCard Inference provider in DSPy?
No. The openai/ prefix with our api_base and key is the whole integration.
Do I need LiteLLM installed? Not for this. DSPy’s setup page treats LiteLLM as an optional extra for compatibility routes. If you also run LiteLLM as a proxy for your team, the LiteLLM guide covers that.
Can I use the Responses API from DSPy?
The guide says “just set model_type="responses" when creating the dspy.LM instance,” and our API speaks Responses. Our Responses reference stores nothing and rejects store: true and previous_response_id. The default chat route is simpler.
Why did a changed key still return an answer?
It probably came from DSPy’s cache. Set cache=False or call dspy.configure_cache with both caches off, then try again.
Are my prompts stored? Not by us: prompts and responses are never logged or stored. DSPy’s own cache stores answers on your disk until you turn it off.