Skip to content

DSPy: using the VIDAI Control Plane as the backend

DSPy's dspy.LM constructor takes an api_base and api_key. Configure the LM once with dspy.configure(lm=...) and every module — Predict, ChainOfThought, ReAct, TypedPredictor, compiled programs — runs through the control plane.

TL;DR

import dspy

lm = dspy.LM(
    "openai/gpt-4o-mini",
    api_base="https://your-vidai-server.example.com/v1",
    api_key="your-vidai-key",
)
dspy.configure(lm=lm)

qa = dspy.Predict("question -> answer")
print(qa(question="reply with: ok").answer)

Prerequisites

  • pip install dspy.
  • Control plane base URL and an API key from API Keys.
  • A model registered on the Models page. The openai/ prefix on the LM identifier tells DSPy's underlying router to use the OpenAI wire shape.

Modules

Every DSPy module inherits the configured LM:

import dspy

class QA(dspy.Signature):
    """Answer the question in one sentence."""
    question: str = dspy.InputField()
    answer:   str = dspy.OutputField()

qa = dspy.ChainOfThought(QA)
print(qa(question="Where is Kyoto?").answer)

ReAct with tools

def search_wiki(query: str) -> str:
    return "Kyoto is a city in Japan."

agent = dspy.ReAct("question -> answer", tools=[search_wiki])
print(agent(question="Where is Kyoto?").answer)

Every reasoning step and every tool round-trip is a control-plane request that appears in Request Logs.

Compilation

DSPy's optimisers (BootstrapFewShot, MIPRO, COPRO) work transparently — the compiler calls the LM many times per example. Set your control plane's Rate Limits generously on the key you use for compilation runs, or the compiler will bounce off the ceiling.

optimiser = dspy.BootstrapFewShot(metric=my_metric)
compiled = optimiser.compile(qa, trainset=train)

Compilation traffic is often best isolated on its own API key so the Chargeback tab separates "programme optimisation" from "programme execution".

Anthropic models

Point at Claude-family models the same way — the anthropic/ prefix routes through the Anthropic wire path:

lm = dspy.LM(
    "anthropic/claude-haiku-4-5",
    api_base="https://your-vidai-server.example.com",
    api_key="your-vidai-key",
)

Note the Anthropic base URL is the root (no /v1).

Verify it works

import dspy

lm = dspy.LM(
    "openai/gpt-4o-mini",
    api_base="https://your-vidai-server.example.com/v1",
    api_key="your-vidai-key",
)
dspy.configure(lm=lm)

probe = dspy.Predict("prompt -> reply")
print(probe(prompt="reply with exactly: ok").reply)

If something's off

Raise an issue at github.com/vidaiUK/vidai-quickstart/issues with your LM config and the module that reproduces the issue. We'll get it sorted.

Where to go next