Use DSPy with Shannon
Configure dspy.LM with the openai/ prefix and Shannon's api_base; modules such as Predict and ReAct then run on Shannon models.
- Tested Nov 7, 2026
- OpenAI Chat Completions
- About 2 min
About DSPy
DSPy is a Python framework for building language-model programs from modules and signatures instead of hand-written prompts, with optimizers that tune them. It calls models through LiteLLM, so any OpenAI-compatible endpoint works, including Shannon.
What you need
- A Shannon API key
- Keys & usage
- Base URL
-
https://api.shannon-ai.com/v1Endpoint:/v1/chat/completions - Every snippet below follows your choice.
Set it up
-
Install DSPy
Shellpip install dspy -
Configure the model
The
openai/prefix selects the OpenAI-compatible route;api_basepoints it at Shannon.Pythonimport dspy lm = dspy.LM("openai/Kimi-K3-uncensored-NVFP4", api_base="https://api.shannon-ai.com/v1", api_key="YOUR_API_KEY") dspy.configure(lm=lm) print(lm("Name three colours a cat can be.")[0]) -
Use a module with a tool
Pythondef get_weather(city: str) -> str: """Weather for a city.""" return f"Sunny, 18 C in {city}" react = dspy.ReAct("question -> answer", tools=[get_weather], max_iters=3) print(react(question="What is the weather in Oslo?").answer)
Check that it works
Send: Run the first sample.
You should see: One sentence with three cat colours.
Models that fit DSPy
Every id below meets what DSPy needs. The first one is the default in the snippets.
| Model id | Context window | Max output | Image input |
|---|---|---|---|
Kimi-K3-uncensored-NVFP4 | 1,022,976 | 262,144 | Yes |
Kimi-K3-uncensored-3BIT-REAP | 225,280 | 225,280 | Yes |
shannon-3 | 196,608 | 65,536 | Yes |
shannon-coder-1 | 131,072 | 65,536 | No |
Good to know
- DSPy caches answers on disk by default; pass
cache=Falsetodspy.LMwhile you test so every call reaches the model. ReActmakes one request per step plus one to extract the answer, so a short tool task takes several requests.- Optimizers such as MIPROv2 send many requests; try them on a model counted in tokens rather than one with a call allowance.
Tips
dspy.inspect_history(n=1)prints the last prompt and answer, which helps when a module misbehaves.- Set a different
dspy.LMper module withmodule.set_lm(...)to mix Shannon models. max_tokensondspy.LMcaps answer length.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
LLM Provider NOT provided | The model id lacks the openai/ prefix. | Write it as openai/<id>. |
| The same answer every time | DSPy's cache. | Pass cache=False or change the input. |
401 Unauthorized | The key is missing, mistyped or rotated. | Copy the key again from Keys & usage; it starts with sk-. |
context_length_exceeded / "prompt is too long" | The conversation is longer than the model's window. | Start a new chat, let the tool compact it, or pick a model with a larger window. |
insufficient_quota | Your balance cannot pay for the request. | Top up or change plan; the request is not retried by itself. |
Questions
Does DSPy work with Shannon?
Yes, through dspy.LM("openai/<id>", api_base="https://api.shannon-ai.com/v1").
Do ReAct tools work?
Yes; we ran a ReAct module that called a tool and answered.