# Use the Python and Node.js SDKs

Use the terminal where you exported `DODO_ROUTER_URL` and `DODO_ROUTER_API_KEY`. The URL ends at your router slug, for example `https://api.dodorouter.com/r/my-agent`. Each example sends one request through your configured routing chain. [Set up your router and environment](/docs/quickstart/).

The OpenAI SDK needs `/v1` in its base URL. The Anthropic SDK adds `/v1/messages` itself and takes the router root. Both accept the router key as their API key. Pass `"default"` for the SDK's model argument. Your routing step selects the serving model.

## Python

In an empty directory, create a virtual environment and install the SDKs.

```bash
python3 -m venv .venv
.venv/bin/python -m pip install openai anthropic
```

### Chat Completions in Python

Save as `chat.py`.

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url=os.environ["DODO_ROUTER_URL"] + "/v1",
    api_key=os.environ["DODO_ROUTER_API_KEY"],
)
reply = client.chat.completions.create(
    model="default",
    messages=[{"role": "user", "content": "Reply with the word pong."}],
)
print(reply.model)
print(reply.choices[0].message.content)
```

```bash
.venv/bin/python chat.py
```

### Messages in Python

Save as `messages.py`.

```python
import os
from anthropic import Anthropic

client = Anthropic(
    base_url=os.environ["DODO_ROUTER_URL"],
    api_key=os.environ["DODO_ROUTER_API_KEY"],
)
reply = client.messages.create(
    model="default",
    max_tokens=128,
    messages=[{"role": "user", "content": "Reply with the word pong."}],
)
print(reply.model)
for block in reply.content:
    if block.type == "text":
        print(block.text)
```

```bash
.venv/bin/python messages.py
```

## Node.js

In an empty directory, create a local package and install the SDKs. Save the examples with the `.mjs` extension so Node runs them as ES modules.

```bash
npm init -y
npm install openai @anthropic-ai/sdk
```

### Chat Completions in Node.js

Save as `chat.mjs`.

```javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: process.env.DODO_ROUTER_URL + "/v1",
  apiKey: process.env.DODO_ROUTER_API_KEY,
});
const reply = await client.chat.completions.create({
  model: "default",
  messages: [{ role: "user", content: "Reply with the word pong." }],
});
console.log(reply.model);
console.log(reply.choices[0].message.content);
```

```bash
node chat.mjs
```

### Messages in Node.js

Save as `messages.mjs`.

```javascript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: process.env.DODO_ROUTER_URL,
  apiKey: process.env.DODO_ROUTER_API_KEY,
});
const reply = await client.messages.create({
  model: "default",
  max_tokens: 128,
  messages: [{ role: "user", content: "Reply with the word pong." }],
});
console.log(reply.model);
for (const block of reply.content) {
  if (block.type === "text") console.log(block.text);
}
```

```bash
node messages.mjs
```

## Verify the result

Each script prints the model that answered on the first line and the assistant's text below it, typically `pong`. To see which steps the router tried, open **Logs** in the dashboard, select the request, and open **Trace**. [Read a request trace](/docs/quickstart/#inspect-this-request).

The OpenAI clients above can also call `client.responses.create` with a text `input` and read `output_text`. [Responses API](/docs/api/responses/).
