Skip to content
DSPy

Frameworks and SDKs

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/v1 Endpoint: /v1/chat/completions
Every snippet below follows your choice.

Set it up

  1. Install DSPy

    Shell
    pip install dspy
  2. Configure the model

    The openai/ prefix selects the OpenAI-compatible route; api_base points it at Shannon.

    Python
    import 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])
  3. Use a module with a tool

    Python
    def 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 idContext windowMax outputImage 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=False to dspy.LM while you test so every call reaches the model.
  • ReAct makes 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

  1. dspy.inspect_history(n=1) prints the last prompt and answer, which helps when a module misbehaves.
  2. Set a different dspy.LM per module with module.set_lm(...) to mix Shannon models.
  3. max_tokens on dspy.LM caps answer length.

Troubleshooting

SymptomCauseFix
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.

Choose your language

All languages are equal. Pick the one you want to browse in.

Europe

Middle East & North Africa

South Asia

Southeast Asia

East Asia

Central Asia & Caucasus

Africa

Oceania

Constructed & Classical