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

# DSPy

> Configure AI Sonar as an OpenAI-compatible language model in DSPy

## Overview

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

<Note>
  **Type**: Programming Framework

  **Primary Path**: OpenAI-compatible language model calls

  **Support Confidence**: Supported custom endpoint path
</Note>

## Environment

```bash theme={null}
export API_KEY="sk-your-api-key"
```

## Configure DSPy

```python theme={null}
import os

import dspy

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

dspy.configure(lm=lm)
```

## Use a Module

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