# Move to OpenDunes

Move an app already running on the OpenAI or Anthropic library: three values change, the code stays.

<div class="prompt">
<p class="prompt-title">Paste this into your agent</p>
<p>Move this project's OpenAI or Anthropic client to OpenDunes. Change three values and nothing else. Base URL: https://opendunes.com/v1 for the OpenAI library, https://opendunes.com for the Anthropic library. Key: read it from the environment variable OPENDUNES_API_KEY; never write it in a file. Model IDs: lab/model, for example anthropic/claude-sonnet-4.5. Docs: https://opendunes.com/docs/llms.txt</p>
</div>

1. [Get a key and a balance](#1-get-a-key-and-a-balance).
2. [Change the base URL and the key](#2-change-the-base-url-and-the-key).
3. [Change the model ID](#3-change-the-model-id).
4. [Send one request to check](#4-send-one-request-to-check).
5. [Read what the answer adds](#5-read-what-the-answer-adds).

## 1. Get a key and a balance

| You need | Where |
|---|---|
| an API key | *API Keys*, in the app: see [API keys](/docs/api-keys) |
| a balance above zero | *Credit*, in the app: deposit by Edahabia or CIB |
| the key in your environment | `export OPENDUNES_API_KEY="…"` |

No foreign card: the balance is in DA, and every request is charged to it.

## 2. Change the base URL and the key

| Library | Base URL | Key |
|---|---|---|
| OpenAI library | `https://opendunes.com/v1` | `OPENDUNES_API_KEY` |
| Anthropic library | `https://opendunes.com` | `OPENDUNES_API_KEY` |

Where your code builds the client, change two arguments.

| Tab | OpenAI library | Anthropic library |
|---|---|---|
| Python | `OpenAI(base_url=…, api_key=…)` | `Anthropic(base_url=…, api_key=…)` |
| JavaScript | `new OpenAI({ baseURL, apiKey })` | `new Anthropic({ baseURL, apiKey })` |
| Go | `option.WithBaseURL(…)`, `option.WithAPIKey(…)` | the same two options |
| cURL | the address, and `Authorization: Bearer` | the address, and `x-api-key` |

<div class="watch-out">
<p>The Anthropic library adds <code>/v1</code> itself. Give it <code>https://opendunes.com</code>, without <code>/v1</code>.</p>
</div>

If your code builds the client with no arguments, the library reads both values from the environment. Set them there and change no line of code.

```bash
# OpenAI library
export OPENAI_BASE_URL="https://opendunes.com/v1"
export OPENAI_API_KEY="$OPENDUNES_API_KEY"

# Anthropic library
export ANTHROPIC_BASE_URL="https://opendunes.com"
export ANTHROPIC_API_KEY="$OPENDUNES_API_KEY"
```

## 3. Change the model ID

Every model is named `lab/model`. Put the lab in front of the name you use today; a Claude model also takes a dot in its version, and no date.

| Library | Model ID today | Model ID on OpenDunes |
|---|---|---|
| OpenAI library | `gpt-6-sol` | `openai/gpt-6-sol` |
| Anthropic library | `claude-opus-5-5` | `anthropic/claude-opus-5.5` |
| Anthropic library | `claude-haiku-4-5-20251001` | `anthropic/claude-haiku-4.5` |

The rest of the request stays as it is: the same body, with the new ID in `model`.

```json
{
  "model": "anthropic/claude-opus-5.5",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": "Two lines to welcome a shop in Oran."
    }
  ]
}
```

<div class="good-to-know">
<p>Copy an ID from its page in <em>Models</em> rather than typing it: see <a href="/docs/models">Models</a>. One key reaches every lab.</p>
</div>

## 4. Send one request to check

Send one short request on the library your app uses. A printed answer and a charge mean the move worked.

### With the OpenAI library

```python
import os
from openai import OpenAI

API_KEY = os.environ["OPENDUNES_API_KEY"]
BASE_URL = "https://opendunes.com/v1"
MODEL = "anthropic/claude-sonnet-4.5"

client = OpenAI(base_url=BASE_URL, api_key=API_KEY)

reply = client.chat.completions.create(
    model=MODEL,
    messages=[{"role": "user", "content": "Reply with OK."}],
)

print(reply.choices[0].message.content)
print(reply.usage.cost)
```

```javascript
import OpenAI from "openai";

const API_KEY = process.env.OPENDUNES_API_KEY;
const BASE_URL = "https://opendunes.com/v1";
const MODEL = "anthropic/claude-sonnet-4.5";

const client = new OpenAI({ baseURL: BASE_URL, apiKey: API_KEY });

const reply = await client.chat.completions.create({
  model: MODEL,
  messages: [{ role: "user", content: "Reply with OK." }],
});

console.log(reply.choices[0].message.content);
console.log(reply.usage.cost);
```

```go
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/openai/openai-go/v3"
	"github.com/openai/openai-go/v3/option"
)

const (
	baseURL = "https://opendunes.com/v1"
	model   = "anthropic/claude-sonnet-4.5"
)

func main() {
	apiKey := os.Getenv("OPENDUNES_API_KEY")

	client := openai.NewClient(
		option.WithBaseURL(baseURL),
		option.WithAPIKey(apiKey),
	)

	params := openai.ChatCompletionNewParams{
		Model: model,
		Messages: []openai.ChatCompletionMessageParamUnion{
			openai.UserMessage("Reply with OK."),
		},
	}
	reply, err := client.Chat.Completions.New(context.TODO(), params)
	if err != nil {
		panic(err)
	}

	fmt.Println(reply.Choices[0].Message.Content)
	fmt.Println(reply.Usage.JSON.ExtraFields["cost"].Raw())
}
```

```bash cURL
ADDRESS="https://opendunes.com/v1/chat/completions"
MODEL="anthropic/claude-sonnet-4.5"

curl "$ADDRESS" \
  -H "Authorization: Bearer $OPENDUNES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL"'",
    "messages": [
      { "role": "user", "content": "Reply with OK." }
    ]
  }'
```

### With the Anthropic library

```python
import os
from anthropic import Anthropic

API_KEY = os.environ["OPENDUNES_API_KEY"]
BASE_URL = "https://opendunes.com"
MODEL = "anthropic/claude-sonnet-4.5"

client = Anthropic(base_url=BASE_URL, api_key=API_KEY)

message = client.messages.create(
    model=MODEL,
    max_tokens=1024,
    messages=[{"role": "user", "content": "Reply with OK."}],
)

print(message.content[0].text)
print(message.usage.cost)
```

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

const API_KEY = process.env.OPENDUNES_API_KEY;
const BASE_URL = "https://opendunes.com";
const MODEL = "anthropic/claude-sonnet-4.5";

const client = new Anthropic({ baseURL: BASE_URL, apiKey: API_KEY });

const message = await client.messages.create({
  model: MODEL,
  max_tokens: 1024,
  messages: [{ role: "user", content: "Reply with OK." }],
});

console.log(message.content[0].text);
console.log(message.usage.cost);
```

```go
package main

import (
	"context"
	"fmt"
	"os"

	"github.com/anthropics/anthropic-sdk-go"
	"github.com/anthropics/anthropic-sdk-go/option"
)

const (
	baseURL = "https://opendunes.com"
	model   = "anthropic/claude-sonnet-4.5"
	prompt  = "Reply with OK."
)

func main() {
	apiKey := os.Getenv("OPENDUNES_API_KEY")

	client := anthropic.NewClient(
		option.WithBaseURL(baseURL),
		option.WithAPIKey(apiKey),
	)

	params := anthropic.MessageNewParams{
		Model:     model,
		MaxTokens: 1024,
		Messages: []anthropic.MessageParam{
			anthropic.NewUserMessage(anthropic.NewTextBlock(prompt)),
		},
	}
	message, err := client.Messages.New(context.TODO(), params)
	if err != nil {
		panic(err)
	}

	fmt.Println(message.Content[0].Text)
	fmt.Println(message.Usage.JSON.ExtraFields["cost"].Raw())
}
```

```bash cURL
ADDRESS="https://opendunes.com/v1/messages"
MODEL="anthropic/claude-sonnet-4.5"

curl "$ADDRESS" \
  -H "x-api-key: $OPENDUNES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL"'",
    "max_tokens": 1024,
    "messages": [
      { "role": "user", "content": "Reply with OK." }
    ]
  }'
```

A 401 means the key did not reach the request: check `OPENDUNES_API_KEY` is set in this terminal. Every other status: [Errors and retries](/docs/errors-and-retries).

## 5. Read what the answer adds

The answer keeps the shape your code already reads. Two things are new, and one status.

| Where | What it is | Illustrative |
|---|---|---|
| `usage.cost`, in the answer | the charge, in DA | `0.020166` DA |
| `X-Balance-Available`, the header | your balance after it, in µDA | `499979834` µDA |
| a 402 | the balance is at zero or below, or cannot pay the request's hold | new requests refused until a deposit |

A streamed answer carries no `X-Balance-Available`: its charge is `usage.cost`, in the closing event. [Streaming](/docs/streaming) shows it, and [Balance and charges](/docs/balance-and-charges) says how each request is charged.

<div class="watch-out">
<p>No library retries a 402: the same request gets the same answer until a deposit covers what the balance owes. If your app retries on every error, let it stop on a 402.</p>
</div>

Next: [Quickstart chat app](/docs/cookbook/quickstart-chat-app) · [OpenAI and Anthropic libraries](/docs/libraries) · [Frameworks](/docs/frameworks)
