TokenLab

Frameworks & Platforms

DSPy

Configure TokenLab as an OpenAI-compatible language model in DSPy

Overview

DSPy can call TokenLab by using the openai/ provider prefix with TokenLab's OpenAI-compatible /v1 endpoint.

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 IDs change over time. Choose a current chat model on the Models page, then compare it on your own DSPy program.

On this page