A question over many documents takes many model calls. Each call sends the model everything the agent has read so far, so the cost adds up.
Compare NVIDIA’s revenue across five annual reports, in three steps:
- Look at the collection: one folder per year.
- Ask the question, and follow the agent through the folders.
- Read the token usage and work out the cost.
Set up
pip install -U pageindexOur read-only demo key reads a collection already on PageIndex Cloud, and your OpenAI key answers the question:
import os
from pageindex import PageIndexClient
os.environ["PAGEINDEX_API_KEY"] = "pageindex_demo_readonly_key"
os.environ["OPENAI_API_KEY"] = "Your OpenAI API key here"
client = PageIndexClient(index="cloud", chat="gpt-5.6-luna")
COLLECTION_ID = "cmu3rp2g9001h0bp4t9uqramg" # NVIDIA, 2022 to 2026Look at the collection
List the folders inside the collection:
client.list_folders(parent_folder_id=COLLECTION_ID){'folders': [{'id': 'cmu3rp4uo001i0bp4w067bq6g',
'name': '2022',
'description': 'NVIDIA fiscal year 2022',
'file_count': 4,
...},
...
{'id': 'cmu3rre91000r0cp4qb90h0fa',
'name': '2026',
'description': 'NVIDIA fiscal year 2026',
'file_count': 4,
...}],
'total': 5}Five folders, 2022 to 2026, with 4 documents each. Only one of the four is the annual report, so the agent has to find it in every folder.
Ask the question
protocol="responses" returns the full response, not just the answer text, so you also get the token counts:
response = client.chat(
"Compare NVIDIA's revenue for last five years.",
folder_id=COLLECTION_ID,
citations=True,
protocol="responses",
)## NVIDIA revenue comparison — last five fiscal years
| Fiscal year | Year ended | Revenue | Year-over-year change |
|---|---|---:|---:|
| FY2022 | Jan. 30, 2022 | **$26.914B** | **+61%** <cite doc="NVIDIA-FY2022-10-K.pdf" page="31" block="p31_table_7"/> |
| FY2023 | Jan. 29, 2023 | **$26.974B** | **Flat** <cite doc="NVIDIA-FY2023-10-K.pdf" page="37" block="p37_table_12"/> |
| FY2024 | Jan. 28, 2024 | **$60.922B** | **+126%** <cite doc="NVIDIA-FY2024-10-K.pdf" page="36" block="p36_table_2"/> |
| FY2025 | Jan. 26, 2025 | **$130.497B** | **+114%** <cite doc="NVIDIA-FY2025-10-K.pdf" page="38" block="p38_table_4"/> |
| FY2026 | Jan. 25, 2026 | **$215.938B** | **+65%** <cite doc="NVIDIA-FY2026-10-K.pdf" page="37" block="p37_table_6"/> |
...The agent went through each year’s folder and found its annual report. Then it read two to four pages of each report: 14 pages across five documents.
Read the usage
You pay for a question by its tokens: roughly, the words sent to the model and the words it writes back. The response counts them in usage:
response["usage"]{'input_tokens': 210613,
'input_tokens_details': {'cached_tokens': 104152, 'cache_write_tokens': 106446},
'output_tokens': 1883,
'output_tokens_details': {'reasoning_tokens': 443},
'total_tokens': 212496}input_tokens: tokens sent to the model, across all its calls.cached_tokens: the part it had seen in an earlier call. They cost a tenth of the normal price.cache_write_tokens: the part saved for later calls. Saving costs 1.25 times the normal price.output_tokens: tokens the model wrote.
At gpt-5.6-luna’s prices per million tokens, $0.20 input, $0.02 cached input and $1.20 output:
| Tokens | Count | Cost |
|---|---|---|
| Input, full price | 15 | $0.000 |
| Input, read from cache | 104,152 | $0.002 |
| Input, written to cache | 106,446 | $0.027 |
| Output | 1,883 | $0.002 |
| Total | $0.031 |
Writing to the cache is most of the cost.
Result
Comparing five annual reports costs about three cents in model fees with gpt-5.6-luna. PageIndex Cloud charges are separate.
The notebook runs this with your key and has a cost calculator for each model: open it in Colab .