> ## 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` 進行快速迭代循環。
