---
title: "Gemini 3.8 Flash on Pydantic AI - Billing ops"
description: "Questions about and changes to a tutoring agency's books, checked to the penny. Tool calling 70%, code mode 90%; rank 21 of 44."
canonical: https://pydantic.dev/models/list/gemini-3.8-flash/billing_ops/
---

# Gemini 3.8 Flash on Pydantic AI - Billing ops

> Questions about and changes to a tutoring agency's books, checked to the penny. Tool calling 70%, code mode 90%; rank 21 of 44.
>
> Markdown copy of https://pydantic.dev/models/list/gemini-3.8-flash/billing_ops/. Index for agents: https://pydantic.dev/models/llms.txt

**Agents: use the API for model information.** It answers a question in one request, where the pages need several.

- Choose a model for an agent: `POST https://pydantic.dev/models/api/select` with a JSON body such as `{"description": "what the agent does"}`. It returns up to five ranked models with reasons. Format: https://pydantic.dev/models/select.md
- Search models by name: `GET https://pydantic.dev/models/api/search?query=<text>`
- List, filter and sort models: `GET https://pydantic.dev/models/api/models`, for example `?weights=open&max_price=2&sort=efficiency`
- One model in full: `GET https://pydantic.dev/models/api/models/<slug>`
- Any other question about the models: `GET https://pydantic.dev/models/api/ask?query=<question>`

Add `intent=<intent>&stack=<stack>&harness=<harness>` to the query string of all but the single model. An `OPTIONS` request to any endpoint returns its schema. The same five are tools of the MCP server at `https://pydantic.dev/models/mcp`. More: https://pydantic.dev/models/usage.md

About the benchmark: https://pydantic.dev/models/benchmarks/billing_ops.md. The model on every Pydantic AI benchmark: https://pydantic.dev/models/list/gemini-3.8-flash/pydantic_ai.md

| Mode         | Score | Tasks passed | Cost  | Requests | Tool calls | Time     |
| ------------ | ----- | ------------ | ----- | -------- | ---------- | -------- |
| Tool calling | 70%   | 7 of 10      | $2.30 | 188      | 702        | 34.0 min |
| Code mode    | 90%   | 9 of 10      | $0.95 | 178      | 178        | 10.1 min |

Each task was run once per mode.

## Review

Written by an LLM from the runs' transcripts.

#### Overall

`gemini-3.8-flash` passed 16 of 20 runs: 7 of 10 in tool calling and 9 of 10 in code mode. Lookups, the two write tasks and both margin questions passed in both modes. All four failures are invoice-audit questions over a whole month of invoices. Total cost was $2.30 for tool calling and $0.95 for code mode.

#### Where it does well

- **Write tasks (4 of 4).** The void-and-reissue ran in the right order, dated today. The payment was allocated oldest due first, 37626 then 12500.
- **Pricing rules.** Split lessons, gross pricing, non-taxable clients and half-up rounding were right in all four margin runs.
- **Self-checking in code mode.** It reconciled tutor pay with the payment order (239575) and 74 computed lines with invoice lines before answering.
- **Recovery.** It hit the 100-nested-call limit once and re-batched at 80 to 96 calls.

#### Mistakes it makes

- **Incomplete audits (3 failures).**
  - `large-wrong_invoices-1` in tool calling opened about 11 of 384 invoices and returned 3 of 12 rows.
  - The same case in code mode checked every line but never looked for repeated lines, so returned 9 of 12.
  - `small-wrong_invoices-1` in tool calling had all the data and missed a wrong-rate line (`INV-00172`).
- **Wasted requests (1 failure).** `large-missed_billed-1` in tool calling spent about 45 requests on void invoices, which the question excludes. It hit the 60-request limit with two of three answers found.
- **Guessed response shapes.** It used `total_pages` or `invoices` instead of `pages` and `items` in four code-mode runs. Each time the first pass was cut to one page or none, and a count check caught it.
- **Sandbox slips.** `next(generator)` raised `TypeError` in four code-mode runs, costing one request each.
- **Void invoices.** It examined them in five of the six audit runs although every question excluded them.

#### Tool calling compared with code mode

Code mode was more accurate (9 against 7 passes) and cheaper on bulk work. The duplicate-lines audit cost $0.05 against $0.62. The missed-attendance audit passed for $0.09, while tool calling failed at $0.77. In tool calling the model reads thousands of JSON lines and does the arithmetic unaided. That worked for one tutor's 75 lessons but not for 384 invoices. On the six small tasks tool calling was the cheaper mode in five. Code mode often used one tool call per `run_code` and added checks, such as 10 requests against 6 for the payment. Request counts were close overall: 188 in tool calling against 178 in code mode.

## Runs

### small-invoice_total-1

**Tool calling: passed.** One `get_invoice` call, then answered 89700; passed in 2 requests. ($0.0063, 2 requests, 7 s)
- Right: Used the invoice `total` directly, in pence

**Code mode: passed.** Fetched the invoice, checked the lines summed to the header total, and answered 89700; passed in 3 requests. ($0.011, 3 requests, 7 s)
- Right: Verified `sum(l["total"]) == inv["total"]` before answering
- Mistake: The extra check made it 3 requests and about twice the cost of tool calling ($0.011 against $0.006)

### small-owed_on_invoices-1

**Tool calling: passed.** Listed the client's invoices and allocations, subtracted the 3563 credit allocation on `INV-00155` and answered 85204; passed in 7 requests. ($0.027, 7 requests, 28 s)
- Right: Counted the credit allocation with no `payment_id` against `INV-00155` (39452 - 3563 + 49315)
- Right: Left out the void invoice `INV-00032`
- Mistake: Two `list_allocations` calls by invoice and a `list_ledger_entries` call repeated data it already had from `list_allocations` by client

**Code mode: passed.** Listed unpaid invoices and allocations, computed 39452 - 3563 + 49315 = 85204 and answered correctly in 8 requests. ($0.034, 8 requests, 22 s)
- Right: Filtered with `status="unpaid"` and subtracted the credit allocation on `INV-00155`
- Mistake: After it had the answer (message 9) it re-listed all invoices and the ledger, two requests that changed nothing
- Mistake: One tool call per `run_code` instead of combining them

### large-tutor_margin-3

**Tool calling: passed.** Listed the tutor's 75 October lessons, attendance and 18 clients, checked two invoices against its own line pricing and answered 120741 correctly in 12 requests. ($0.18, 12 requests, 3.8 min)
- Right: Batched `get_client` calls five at a time
- Right: Cross-checked a non-taxable client invoice (`INV-06243`) and a split-lesson invoice (`INV-06194`) before answering
- Right: Handled split lessons, gross pricing, non-taxable clients and one-off tutor pay correctly without code
- Mistake: All arithmetic over 74 charged lines was done without any tool; right this time, but nothing in the trace verifies it
- Mistake: `list_invoices` for all of `2026-11-01` returned a 100-row page it barely used

**Code mode: passed.** Priced every charged attendance in code with `Decimal` half-up rounding, reconciled tutor pay with the payment order (239575) and all 74 lines with invoice lines, and answered 120741; passed in 27 requests. ($0.13, 27 requests, 1.7 min)
- Right: Tutor pay matched the payment order total exactly
- Right: Computed net matched the sum of invoice line nets (360316) with 0 mismatches
- Right: Checked the date edges with a wider `list_lessons` call
- Mistake: Used only page 1 of `list_lessons` without checking `pages`; it happened to hold all 75 lessons
- Mistake: `asyncio` not imported (message 11) and `next(generator)` `TypeError` (message 35) each cost a request
- Mistake: About ten requests of spot checks on single invoices came before the full reconciliation that made them unnecessary

### small-tutor_margin-3

**Tool calling: passed.** Listed 39 lessons and attendance, fetched seven clients and six invoices one call at a time, and answered 65045 correctly in 26 requests. ($0.14, 26 requests, 2.6 min)
- Right: Checked its pricing against real invoice lines for six clients
- Right: Treated the two non-taxable clients (`CL-0030`, `CL-0037`) correctly
- Mistake: Seven `get_client` calls and six `list_invoices` plus `get_invoice` pairs were issued one per request; the large run of the same question batched them and took 12 requests
- Mistake: Arithmetic done with no tool

**Code mode: passed.** Paged 39 lessons, priced every charged line in code, matched 33 of 33 invoiced lines and answered 65045; passed in 21 requests. ($0.10, 21 requests, 53 s)
- Right: Computed net 187435 and tutor pay 122390 with half-up `Decimal` rounding
- Right: Its computed lines matched all 33 lines found on the 1 November invoices
- Right: Noticed four lessons missing from those invoices and investigated before trusting the figure
- Mistake: Message 21: tutor pay multiplies every lesson's `tutor_rate` by hours without branching on `charge_type`; correct only if none of these lessons is one-off
- Mistake: Message 3: `.get` called on a list raised `AttributeError`
- Mistake: Message 25: looped `get_invoice` over all 37 invoices sent on 1 November instead of only this tutor's clients

### large-duplicate_lines-1

**Tool calling: passed.** Paged all 394 October invoices and called `get_invoice` on essentially every one in parallel batches of up to 41, then spotted the three duplicated lines by reading; passed, but at $0.62 and 27 requests. ($0.62, 27 requests, 4.9 min)
- Right: Fetched all four `list_invoices` pages and covered the non-void invoices in full rather than sampling
- Right: Confirmed the three hits with `list_attendance` on `LS-044150`, `LS-042250`, `LS-044126` before answering
- Mistake: Messages 7-22: fetched void invoices (`INV-05811`, `INV-05817`, `INV-05959` and others), a `list_lessons` page for September and attendance for `LS-042858`, none of which the question needs
- Mistake: Message 25-30: re-listed with `status: unpaid` and fetched those invoices separately, then fetched the rest again by range, so the context grew to about 670k characters
- Mistake: Duplicates were found by reading roughly 2,600 lines of raw JSON with no tool to count them; correct here but fragile

**Code mode: passed.** Wrote a per-invoice duplicate check, fixed a pagination bug and a nested-call limit, then scanned all 384 non-void invoices in batches of 80; passed in 13 requests for $0.05. ($0.048, 13 requests, 30 s)
- Right: Noticed that 100 invoices was suspicious, inspected the response keys and repaged with `pages` to get 394
- Right: After the 100-nested-call error it split the work into `asyncio.gather` batches of 80
- Right: Printed the duplicated lines for the three hits before answering
- Mistake: Message 1: looped on `res.get("total_pages", 1)`, a key that does not exist, so the first pass saw only page 1 and found nothing
- Mistake: Message 9: asked for 384 `get_invoice` calls in one `run_code` and hit the 100-call limit
- Mistake: Two requests spent just printing `res.keys()` and counts

### large-missed_billed-1

**Tool calling: error.** Spent about 45 single-call requests comparing void invoices with their reissues, then switched to scanning September lessons and attendance, found two of the three invoices and hit the 60-request limit with no answer. ($0.77, 60 requests, 15.5 min)
- Right: From message 93 it used the right method: page `list_lessons` for September, batch `list_attendance`, look for `missed` with `invoiced: true`, then `list_invoices` by client
- Right: Had already confirmed `INV-05846` (message 97) and `INV-06080` (message 113) when it stopped
- Mistake: Messages 7-92: investigated the ten void invoices and their replacements (`INV-06145` to `INV-06154`) one `get_invoice` or `list_attendance` call per request, although the question excludes void invoices
- Mistake: Fetched only pages 1 and 4 of `list_invoices`, so it never held the full October invoice list
- Mistake: Started the full lesson scan at about request 47, with roughly 30 pages of lessons to read; it reached page 21 or so before `UsageLimitExceeded`
- Mistake: Should have begun with the lesson and attendance scan in five-call parallel batches, which it only did at the end

**Code mode: passed.** Fetched all 384 non-void invoices in four batches, pulled attendance for 2,655 lessons in 27 chunks, and matched lines to `missed` attendance; passed in 18 requests for $0.09. ($0.086, 18 requests, 55 s)
- Right: Joined invoice lines to attendance on `(lesson_id, student_id)` and found exactly three matches
- Right: Sized batches at 96 to stay under the nested-call limit
- Mistake: Message 1: read `res.get("invoices")` and `total_pages`, both wrong keys, and got 0 invoices; fixed after printing one page
- Mistake: Message 27: `next(generator)` raised `TypeError` in the sandbox; rewritten as a loop
- Mistake: Messages 31-34: fetched and checked the ten void invoices, which the question excludes

### large-wrong_invoices-1

**Tool calling: failed.** Looked only at invoice headers, picked out three invoices where a non-taxable client was charged tax, and returned those; 9 of the 12 wrong invoices were missed. ($0.22, 19 requests, 2.1 min)
- Right: The three rows it returned (`INV-05851` 1050, `INV-06016` 1150, `INV-06105` 1875) have the correct amounts
- Right: Fetched all four pages of `list_invoices`
- Mistake: Called `get_invoice` on only about 11 of 384 non-void invoices, several of them void ones (`INV-05811`, `INV-05817`, `INV-06100`), so it could not see line-level errors
- Mistake: Never checked lines against attendance, so missed the missed-student charges on `INV-05821`, `INV-05846`, `INV-06080`
- Mistake: Never checked for repeated lines, so missed `INV-06060`, `INV-06073`, `INV-06097`
- Mistake: Never compared line amounts with lesson rates, so missed `INV-05791`, `INV-05877`, `INV-06017`
- Mistake: Read one page of `list_lessons` and two pages of `list_ledger_entries` for credit notes, then stopped at 19 requests with 41 left

**Code mode: failed.** Recomputed every line on 384 invoices from lessons, attendance and client tax status and found 9 wrong invoices with correct amounts, but never checked for repeated lines and so missed three; failed after 45 requests. ($0.31, 45 requests, 3.1 min)
- Right: All nine returned rows have the right amounts, covering missed-student charges, wrong rates and tax on non-taxable clients
- Right: Fetched 384 invoices, 2,655 lessons, 3,148 attendance records and 384 clients in batches under the call limit
- Mistake: The check at message 75 validates each line on its own, so a line that appears twice passes twice; `INV-06060` (3563), `INV-06073` (4500) and `INV-06097` (9900) were missed
- Mistake: It ran exactly this `Counter` on `(lesson_id, student_id)` in the small version of the case but not here; rebuilding the expected lines per client, as it did there, would also have caught them
- Mistake: Message 55 ran a long script that returned `{}`; the `att["attendance"]` key error and a `next(generator)` error cost further requests
- Mistake: Messages 33-39 examined void invoices and `search_clients(name="")` to no purpose

### small-wrong_invoices-1

**Tool calling: failed.** Fetched all 37 invoices, all clients, all September lessons and attendance, but returned three of the four wrong invoices; `INV-00172` (600 overcharged) was missed. ($0.28, 22 requests, 2.8 min)
- Right: Gathered complete data: every invoice, client, lesson page and attendance batch
- Right: Got `INV-00158` 4050 (repeated line), `INV-00162` 863 (tax on a non-taxable client) and `INV-00176` 6000 right
- Mistake: Did not notice that the `LS-001295` line on `INV-00172` was billed above the lesson's rate, although both the invoice and the lesson were in context; comparing about 280 lines against rates by reading is where it slipped
- Mistake: Fetched `list_lessons` with `status: cancelled` and several one-lesson `list_attendance` calls that added nothing

**Code mode: passed.** Recomputed each line, then rebuilt what every client should have been billed from September lessons and compared totals, finding all four wrong invoices; passed in 27 requests. ($0.15, 27 requests, 1.8 min)
- Right: Line check found the tax and rate errors (`INV-00162`, `INV-00172`, `INV-00176`); a `Counter` on `(lesson_id, student_id)` found the repeated line on `INV-00158`
- Right: The second pass, comparing expected lines per client with the invoice total, gave the four overcharges 4050, 863, 600 and 6000 directly
- Right: Checked August for uninvoiced lessons before trusting the September-only rebuild
- Mistake: Used `res.get("total_pages", 1)` three times (messages 1, 31, 33); harmless for the 37 invoices, but it truncated September lessons to 100 of 315 until fixed at message 37
- Mistake: Message 9: `next(generator)` `TypeError`; message 31: passed a datetime to `list_lessons(end=...)`, which wants a date

### large-correction-2

**Tool calling: passed.** Read the invoice and settings, marked the 7 October lesson `missed`, voided `INV-06372` and reissued the other three lessons as `INV-06548`; passed in 7 requests. ($0.026, 7 requests, 37 s)
- Right: Correct order: `update_attendance` (`LS-045235`, `missed`), then `void_invoice` and `create_invoice`, both dated `2026-11-13`
- Right: Reissued exactly the three remaining lines; new invoice total 17100 was auto-paid from the released credit
- Right: Verified afterwards with `list_attendance` on all four lessons
- Mistake: `get_settings` call at the start was not needed for this change (minor)

**Code mode: passed.** Read the invoice, attendance and settings, then did the attendance update, void and reissue in one `run_code` block and checked the ledger; passed in 6 requests. ($0.028, 6 requests, 18 s)
- Right: One script ran `update_attendance`, `void_invoice` and `create_invoice` in the right order, building the new lines by filtering out `LS-045235`
- Right: Checked the ledger afterwards: credit note 22800 and new invoice -17100 both dated `2026-11-13`
- Mistake: Three separate read-only `run_code` calls at the start could have been one

### large-record_payment-1

**Tool calling: passed.** Found the client, read invoices, allocations and ledger, then recorded 50126 with explicit allocations of 37626 to `INV-02840` and 12500 to `INV-03247`; passed in 6 requests. ($0.030, 6 requests, 68 s)
- Right: Worked out the remaining 37626 on `INV-02840` (58778 less the existing 21152 allocation) and put the remainder on the next oldest due invoice
- Right: Converted £501.26 to 50126 pence and dated the payment `2026-11-13`

**Code mode: passed.** Computed the remaining amount on each unpaid invoice in code, recorded 50126 with allocations 37626 and 12500, and confirmed `INV-02840` became `paid`; passed in 10 requests. ($0.041, 10 requests, 29 s)
- Right: Printed remaining balances per unpaid invoice in due-date order before allocating
- Right: Checked there was no existing unallocated credit (payments 241190 equal allocations 241190)
- Right: Re-read both invoices after `record_payment` to confirm statuses
- Mistake: `get_client` and `get_settings` calls were not needed; 10 requests against 6 in tool calling
