فارسی Docs Developer guide

Coding with DaLAi

Setting up Claude Code, opencode, Cline, Continue and Aider, choosing a model for code, and keeping costs under control.

AI coding tools run inside your editor and get their help from a language model. DaLAi supplies that model; the tool itself stays the same.

Claude Code

Claude Code is Anthropic's own command-line tool, and it works with DaLAi. Its setup differs from the other tools on this page: you do not enter the address and key in the app's settings; instead, you set three environment variables.

In Windows PowerShell:

$env:ANTHROPIC_BASE_URL="https://dalai.ir"
$env:ANTHROPIC_AUTH_TOKEN="sk-YOUR-KEY"
$env:ANTHROPIC_MODEL="claude-sonnet-4-5"
claude

On macOS and Linux:

export ANTHROPIC_BASE_URL=https://dalai.ir
export ANTHROPIC_AUTH_TOKEN=sk-YOUR-KEY
export ANTHROPIC_MODEL=claude-sonnet-4-5
claude

Three points; if any of them is missed, it will not work:

If you want the tool's auxiliary tasks to work properly too, also add ANTHROPIC_DEFAULT_HAIKU_MODEL=claude-haiku-4-5. Claude Code calls a small model for its own lightweight tasks, and that model's default name is dated as well, so without this variable you get the same error as above.

The first message of every session is expensive. Before it even gets to your task, Claude Code sends a system prompt of about 35,000 tokens. In our test, a short session with just a single file read took nearly half a dollar from the balance. Do not start with a balance close to zero, and after your first session, check your actual cost in Usage Logs.

Cline

A VS Code extension that can read files, modify them and run commands.

Continue

For VS Code and JetBrains. In config.yaml:

models:
  - name: DaLAi
    provider: openai
    apiBase: https://dalai.ir/v1
    apiKey: sk-YOUR-KEY
    model: claude-sonnet-4-5

Aider

A command-line tool that works directly with git:

aider --openai-api-base https://dalai.ir/v1 \
      --openai-api-key sk-YOUR-KEY \
      --model claude-sonnet-4-5

opencode

An open-source command-line coding tool that reads files, modifies them and runs commands. It has been tested with this service: version 1.18 read a local file with its own tool and gave the correct answer.

Install it with npm (other methods are on the opencode website). On Windows, opencode itself recommends running it in WSL.

npm i -g opencode-ai

Then create the opencode.json file, either in the project root or, for all projects, at ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "dalai": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "DaLAi",
      "options": {
        "baseURL": "https://dalai.ir/v1",
        "apiKey": "{env:DALAI_API_KEY}"
      },
      "models": {
        "claude-sonnet-4-5": { "name": "Claude Sonnet 4.5" },
        "claude-haiku-4-5": { "name": "Claude Haiku 4.5" }
      }
    }
  },
  "model": "dalai/claude-sonnet-4-5"
}

Put the key in the DALAI_API_KEY environment variable and run opencode. In Windows PowerShell:

$env:DALAI_API_KEY="sk-YOUR-KEY"
opencode

On macOS and Linux:

export DALAI_API_KEY=sk-YOUR-KEY
opencode

At every step, opencode also sends its system prompt and its tool definitions. In our test, each step had about 8,000 input tokens before any file from the project was added to it. Check the actual cost in Usage Logs.

Which model for code

The practical approach: start with a mid-sized model and move up only when you get stuck. The opposite, always staying on the most expensive model, is the biggest waste of money in coding.

Why coding costs more than chat

Coding tools also send the contents of your files to the model. A simple question about one function can carry several thousand input tokens, because the whole file goes along with it. In agent mode, where the tool works through several steps in a row, this repeats at every step.

Ways to reduce the cost:

A full explanation of how costs are calculated is in Wallet, top-ups and billing.