Skip to main content

Overview

DSPy can call TokenLab by using the openai/ provider prefix with TokenLab’s OpenAI-compatible /v1 endpoint.
Type: Programming FrameworkPrimary Path: OpenAI-compatible language model callsSupport Confidence: Supported custom endpoint path

Environment

export TOKENLAB_API_KEY="sk-your-tokenlab-key"

Configure DSPy

import os

import dspy

lm = dspy.LM(
    "openai/claude-sonnet-5",
    api_key=os.environ["TOKENLAB_API_KEY"],
    api_base="https://api.tokenlab.sh/v1",
)

dspy.configure(lm=lm)

Use a Module

qa = dspy.ChainOfThought("question -> answer")

response = qa(question="What should I monitor in an LLM gateway?")
print(response.answer)

Model Suggestions

Use gpt-5.4-mini for quick experiments, claude-sonnet-5 for stronger reasoning traces, and deepseek-v4-flash for fast iteration loops.