> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# DSPy

> 在 DSPy 中将 TokenLab 配置为 OpenAI 兼容的语言模型

## 概述

DSPy 可以通过使用 `openai/` 提供程序前缀以及 TokenLab 的 OpenAI 兼容 `/v1` 端点来调用 TokenLab。

<Note>
  **类型**: 编程框架

  **主要路径**: OpenAI 兼容语言模型调用

  **支持置信度**: 支持自定义端点路径
</Note>

## 环境

```bash theme={null}
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
```

## 配置 DSPy

```python theme={null}
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)
```

## 使用模块

```python theme={null}
qa = dspy.ChainOfThought("question -> answer")

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

## 模型建议

使用 `gpt-5.4-mini` 进行快速实验，使用 `claude-sonnet-5` 获取更强的推理轨迹，并使用 `deepseek-v4-flash` 进行快速迭代循环。
