# Review by a stronger model

Let a fast model do the work, and give it a stronger model to consult on the one decision that needs it.

1. [Pick the two models](#1-pick-the-two-models).
2. [Give the worker a reviewer to call](#2-give-the-worker-a-reviewer-to-call).
3. [Send the reviewer a short brief](#3-send-the-reviewer-a-short-brief).
4. [Offer the reviewer only when it earns its cost](#4-offer-the-reviewer-only-when-it-earns-its-cost).
5. [Read what each model cost](#5-read-what-each-model-cost).

## 1. Pick the two models

Two seats, two models. The worker reads the task and writes the answer. The reviewer answers one question, briefly, when the worker asks it.

| Seat | Does | Model in this recipe |
|---|---|---|
| worker | reads the task, drafts the answer, decides when to ask | `anthropic/claude-sonnet-4.5` |
| reviewer | answers one question, in a few lines | `anthropic/claude-opus-5.5` |

The samples below put `anthropic/claude-sonnet-4.5` in both seats, so they run as they stand. Set `REVIEWER` to the reviewer's model ID, from the table or from [Models](/docs/models).

## 2. Give the worker a reviewer to call

The reviewer is a tool in the worker's `tools`, like any function of yours ([Tools and function calling](/docs/tools)). When the worker calls `ask_reviewer`, your code sends its question to the reviewer's model, in a request of its own, and returns the reply as the call's result. The worker reads it and finishes the answer.

Yacine builds the delivery app for a pharmacy chain in Sétif. His agent checks each change before it ships, and a change that touches payments goes past the stronger model first.

```python
import json
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"
REVIEWER = "anthropic/claude-sonnet-4.5"
WORKER_BRIEF = (
    "You check changes before they ship. When a decision is risky, call "
    "ask_reviewer once, with a short question: the decision, the files, "
    "the risks. Never paste whole diffs."
)
REVIEWER_BRIEF = (
    "You review engineering plans. Name hidden assumptions, missing "
    "rollback steps and missing tests. Five lines at most."
)
TASK = (
    "Change: move payment records to a new monthly table.\n"
    "Files: db/0042_payments.sql, app/payments/save.py\n"
    "Question: ship it, or send it back?"
)
SIGNALS = ["schema change", "payment path", "no rollback step"]
RISKY = ["schema change", "payment path", "no tests"]
MAX_STEPS = 6

client = OpenAI(base_url=BASE_URL, api_key=API_KEY)
spent = {"worker": 0.0, "reviewer": 0.0}


def ask_reviewer(question):
    reply = client.chat.completions.create(
        model=REVIEWER,
        max_tokens=300,
        messages=[
            {"role": "system", "content": REVIEWER_BRIEF},
            {"role": "user", "content": question},
        ],
    )
    spent["reviewer"] += reply.usage.cost
    return reply.choices[0].message.content


review_tool = {
    "type": "function",
    "function": {
        "name": "ask_reviewer",
        "description": "Ask a senior reviewer one short question.",
        "parameters": {
            "type": "object",
            "properties": {"question": {"type": "string"}},
            "required": ["question"],
        },
    },
}

offer = any(signal in RISKY for signal in SIGNALS)
extra = {"tools": [review_tool]} if offer else {}
task = TASK + "\nSignals: " + ", ".join(SIGNALS)
messages = [
    {"role": "system", "content": WORKER_BRIEF},
    {"role": "user", "content": task},
]

for step in range(MAX_STEPS):
    reply = client.chat.completions.create(
        model=MODEL,
        messages=messages,
        **extra,
    )
    spent["worker"] += reply.usage.cost
    message = reply.choices[0].message
    if not message.tool_calls:
        break
    messages.append(message)
    for call in message.tool_calls:
        question = json.loads(call.function.arguments)["question"]
        messages.append(
            {
                "role": "tool",
                "tool_call_id": call.id,
                "content": ask_reviewer(question),
            }
        )

print(message.content)
print(spent)
```

```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 REVIEWER = "anthropic/claude-sonnet-4.5";
const WORKER_BRIEF =
  "You check changes before they ship. When a decision is risky, call " +
  "ask_reviewer once, with a short question: the decision, the files, " +
  "the risks. Never paste whole diffs.";
const REVIEWER_BRIEF =
  "You review engineering plans. Name hidden assumptions, missing " +
  "rollback steps and missing tests. Five lines at most.";
const TASK =
  "Change: move payment records to a new monthly table.\n" +
  "Files: db/0042_payments.sql, app/payments/save.py\n" +
  "Question: ship it, or send it back?";
const SIGNALS = ["schema change", "payment path", "no rollback step"];
const RISKY = ["schema change", "payment path", "no tests"];
const MAX_STEPS = 6;

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

async function askReviewer(question) {
  const reply = await client.chat.completions.create({
    model: REVIEWER,
    max_tokens: 300,
    messages: [
      { role: "system", content: REVIEWER_BRIEF },
      { role: "user", content: question },
    ],
  });
  spent.reviewer += reply.usage.cost;
  return reply.choices[0].message.content;
}

const reviewTool = {
  type: "function",
  function: {
    name: "ask_reviewer",
    description: "Ask a senior reviewer one short question.",
    parameters: {
      type: "object",
      properties: { question: { type: "string" } },
      required: ["question"],
    },
  },
};

const offer = SIGNALS.some((signal) => RISKY.includes(signal));
const extra = offer ? { tools: [reviewTool] } : {};
const task = TASK + "\nSignals: " + SIGNALS.join(", ");
const messages = [
  { role: "system", content: WORKER_BRIEF },
  { role: "user", content: task },
];
let message;

for (let step = 0; step < MAX_STEPS; step++) {
  const reply = await client.chat.completions.create({
    model: MODEL,
    messages,
    ...extra,
  });
  spent.worker += reply.usage.cost;
  message = reply.choices[0].message;
  if (!message.tool_calls?.length) break;
  messages.push(message);
  for (const call of message.tool_calls) {
    const { question } = JSON.parse(call.function.arguments);
    messages.push({
      role: "tool",
      tool_call_id: call.id,
      content: await askReviewer(question),
    });
  }
}

console.log(message.content);
console.log(spent);
```

```go
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"slices"
	"strconv"
	"strings"

	"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"
	reviewer    = "anthropic/claude-sonnet-4.5"
	workerBrief = "You check changes before they ship. When a decision " +
		"is risky, call ask_reviewer once, with a short question: the " +
		"decision, the files, the risks. Never paste whole diffs."
	reviewerBrief = "You review engineering plans. Name hidden " +
		"assumptions, missing rollback steps and missing tests. " +
		"Five lines at most."
	task = "Change: move payment records to a new monthly table.\n" +
		"Files: db/0042_payments.sql, app/payments/save.py\n" +
		"Question: ship it, or send it back?"
	maxSteps = 6
)

var (
	signals = []string{"schema change", "payment path", "no rollback step"}
	risky   = []string{"schema change", "payment path", "no tests"}
)

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

	client := openai.NewClient(
		option.WithBaseURL(baseURL),
		option.WithAPIKey(apiKey),
	)
	spent := map[string]float64{"worker": 0, "reviewer": 0}

	askReviewer := func(question string) string {
		params := openai.ChatCompletionNewParams{
			Model:     reviewer,
			MaxTokens: openai.Int(300),
			Messages: []openai.ChatCompletionMessageParamUnion{
				openai.SystemMessage(reviewerBrief),
				openai.UserMessage(question),
			},
		}
		reply, err := client.Chat.Completions.New(context.TODO(), params)
		if err != nil {
			panic(err)
		}
		spent["reviewer"] += charge(reply)
		return reply.Choices[0].Message.Content
	}

	question := map[string]any{"type": "string"}
	reviewTool := openai.ChatCompletionFunctionTool(
		openai.FunctionDefinitionParam{
			Name: "ask_reviewer",
			Description: openai.String(
				"Ask a senior reviewer one short question."),
			Parameters: openai.FunctionParameters{
				"type":       "object",
				"properties": map[string]any{"question": question},
				"required":   []string{"question"},
			},
		},
	)

	offer := slices.ContainsFunc(signals, func(signal string) bool {
		return slices.Contains(risky, signal)
	})
	params := openai.ChatCompletionNewParams{
		Model: model,
		Messages: []openai.ChatCompletionMessageParamUnion{
			openai.SystemMessage(workerBrief),
			openai.UserMessage(
				task + "\nSignals: " + strings.Join(signals, ", ")),
		},
	}
	if offer {
		params.Tools = []openai.ChatCompletionToolUnionParam{reviewTool}
	}

	var message openai.ChatCompletionMessage
	for step := 0; step < maxSteps; step++ {
		reply, err := client.Chat.Completions.New(context.TODO(), params)
		if err != nil {
			panic(err)
		}
		spent["worker"] += charge(reply)
		message = reply.Choices[0].Message
		if len(message.ToolCalls) == 0 {
			break
		}
		params.Messages = append(params.Messages, message.ToParam())
		for _, call := range message.ToolCalls {
			var args struct{ Question string }
			json.Unmarshal([]byte(call.Function.Arguments), &args)
			answer := askReviewer(args.Question)
			result := openai.ToolMessage(answer, call.ID)
			params.Messages = append(params.Messages, result)
		}
	}

	fmt.Println(message.Content)
	fmt.Println(spent)
}

func charge(reply *openai.ChatCompletion) float64 {
	cost := reply.Usage.JSON.ExtraFields["cost"].Raw()
	value, _ := strconv.ParseFloat(cost, 64)
	return value
}
```

```bash cURL
ADDRESS="https://opendunes.com/v1/chat/completions"
MODEL="anthropic/claude-sonnet-4.5"
WORKER_BRIEF="You check changes before they ship. When a decision is risky, \
call ask_reviewer once, with a short question: the decision, the files, \
the risks. Never paste whole diffs."
TASK="Change: move payment records to a new monthly table. \
Files: db/0042_payments.sql, app/payments/save.py. \
Question: ship it, or send it back? \
Signals: schema change, payment path, no rollback step"

curl "$ADDRESS" \
  -H "Authorization: Bearer $OPENDUNES_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "'"$MODEL"'",
    "messages": [
      {
        "role": "system",
        "content": "'"$WORKER_BRIEF"'"
      },
      {
        "role": "user",
        "content": "'"$TASK"'"
      }
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "ask_reviewer",
          "description": "Ask a senior reviewer one short question.",
          "parameters": {
            "type": "object",
            "properties": {
              "question": {
                "type": "string"
              }
            },
            "required": ["question"]
          }
        }
      }
    ]
  }'
```

The cURL sample is the worker's first turn: its answer carries the `ask_reviewer` call your code runs.

<div class="good-to-know">
<p>The same review can run in one request, with the advisor helper, <code>opendunes:advisor</code>: OpenDunes calls the stronger model for the worker, and you write no loop. <a href="/docs/helpers">Helpers</a> shows how. The loop above is the version you own: you see every question, and you decide what the reviewer reads.</p>
</div>

## 3. Send the reviewer a short brief

The reviewer's request is a request like any other, charged on its own. The reviewer sees its brief and the worker's question, and nothing else: not the conversation, not the task. This is the request `ask_reviewer` sends, with the reviewer's model in place.

```json
{
  "model": "anthropic/claude-opus-5.5",
  "max_tokens": 300,
  "messages": [
    {
      "role": "system",
      "content": "You review engineering plans. Five lines at most."
    },
    {
      "role": "user",
      "content": "Payments move to a monthly table, no rollback. Safe to ship?"
    }
  ]
}
```

`max_tokens` caps the reviewer's answer, and with it the reviewer's share of the charge.

| Goes in the question | Stays out |
|---|---|
| the decision to review | the whole conversation |
| the files it touches | whole diffs and logs |
| the risks the worker sees | keys, customer data |
| the answer it expects: ship or send back | anything the decision does not turn on |

<div class="dont">
<p>Don't forward the whole conversation to the reviewer. It reads every token you send, at its own rates, and the stronger model's rates are the higher ones.</p>
</div>

<div class="do">
<p>Tell the worker, in its brief, what a question to the reviewer holds, and cap the reviewer's answer with <code>max_tokens</code>.</p>
</div>

## 4. Offer the reviewer only when it earns its cost

Most tasks never need the reviewer. The samples offer `ask_reviewer` only when a task carries a signal from `RISKY`; for any other task, `tools` is not sent, and the request stays on the worker alone.

| Signal on the task | The worker gets |
|---|---|
| none from `RISKY` | no reviewer: one model, one charge per turn |
| a schema change, a payment path, no tests | `ask_reviewer`, to call once if it helps |

Your code knows these signals before the first request: the files a change touches, whether tests ran, how much money moves. Set them in `SIGNALS` from there.

## 5. Read what each model cost

Each request is charged on its own, at its model's rates, and `usage.cost` on each answer carries its charge in DA. The samples keep two sums: `worker`, every turn of the worker, and `reviewer`, every call to the reviewer. *Activity*, in the app, lists each request under its model. What to do on each status: [Errors and retries](/docs/errors-and-retries).

A reviewer that is a person, not a model: [Human approval on tool calls](/docs/cookbook/human-approval-on-tool-calls).
