---
title: "Stage 5: APIs and choosing models"
---

# 5. APIs and choosing models

**14:45–15:25**

An API accepts a request from a program. A data API can return records as JSON. A model API can return a judgement about a text and information about the run.
You will compare models and estimate the cost of coding the whole NHS collection through three routes.

Use the [full NHS teaching file](../practice-data/survey-candidates/nhs-fft-patient-feedback/nhs-fft-clean.csv), the [OpenAI demo notes](../demo/api/RUNBOOK.md) and the [saved example](../demo/api/saved-run/README.md). The saved example uses fictional comments and a mock response. It shows the files the demo keeps. [NHS source and licence](../practice-data/survey-candidates/nhs-fft-patient-feedback/SOURCE.md)

## Steps

1. **Follow one request and reply · 4 minutes.** Paste:

   > Read the saved example under demo/api/saved-run/. Show me the request, raw response and run notes for item 001. Point out which field holds the comment and which holds the model's reply, then show me the corresponding row in results.csv. Explain which fields would let me compare this run with a later one. Keep this exercise on the saved files.

2. **Make a model-choice table · 10 minutes.** Use the [public Artificial Analysis table](https://artificialanalysis.ai/models) or, if you want to try the data API, get an optional free key using the account links in the [API notes](../demo/api/artificial-analysis.md). Enter it only into a hidden prompt in your own terminal. Paste:

   > Build a table for choosing a model to code 6,205 short NHS comments. Use public Artificial Analysis figures or the free model list if I choose the API. For the API, first make a small Python standard-library script I can run in my own terminal on Mac or Windows. Have it read the key from a hidden prompt and save only the response data. Keep the key out of chat, commands and files. Compare intelligence, input and output price, speed and context. Show units, dates and links for the figures, including provider documentation if model context is missing. Write “Source: Artificial Analysis” with a link to artificialanalysis.ai below the table. Suggest two models to try on the same checked sample and say why.

3. **Estimate three routes · 8 minutes.** Paste:

   > Use nhs-fft-clean.csv and our model table to estimate the cost of coding all 6,205 comments. Compare subagents within a subscription, a model API and a local model. Show your assumptions about tokens, batch size, repeated instructions and likely output length. For the OpenAI API, show standard and batch pricing from demo/api/prices.json. Distinguish estimated API charges from subscription limits and local runtime. Mark values you cannot estimate. Save the calculation with the pricing date and model version, plus a short plan for checking a sample on reruns.

   **Check by hand.** Match one model's price and units to its source. Recalculate one line of the API estimate. Look at the saved example and find what would let you distinguish a model-version change from an instruction change.

## If you get stuck

Use the public model table without a key. Copy two models' figures into the chat if the agent cannot open the site. If you only have the saved demo, use its sample token counts to practise the calculation and label it as an illustration.

## If you finish early

Use the same codebook on the same small set of comments twice in fresh chats. Keep each result and compare labels by comment ID. Read one disagreement and describe the evidence for each label.
