Guide

Apple Health in Codex

OpenAI's Codex can read your Apple Health data through HealthAPI's MCP server, in the terminal or in your editor. One command adds it and starts the sign-in, and you approve it on your iPhone. Then Codex can write code against your real sleep, heart and activity numbers.

  • CLI and IDE extension
  • 8 read-only tools
  • Updated 22 October 2026

HealthAPI: Free for 2 days, no card needed. Then an optional 7-day free trial when you subscribe.

health · codex

$codex mcp add healthapi --url https://healthapi.app/mcp

Successfully logged in.

>Which of the last 30 nights did I sleep under 6 hours? Save them as a CSV.

healthapi · get_sleeplast 30 nights

Editedshort_nights.csv

4 nights under 6 h: Sep 29, Oct 6, Oct 13 and Oct 19. Saved them to short_nights.csv.

HealthAPI on your iPhone

“Codex” wants to read your health data

We can't confirm who runs this app. Only approve it if you set it up yourself and trust it.

Approve

What you need

  • An iPhone on iOS 15 or later with Apple Health. Apple Watch data comes along too.
  • The HealthAPI app. Free for 2 days, no card needed. Then an optional 7-day free trial when you subscribe. The preview includes 25 requests a day. When the 2 days are up, AI apps and the API stop reading your data until you choose a plan in the app. Your synced data is kept for about 5 weeks, so subscribing picks up where you left off. Pro is $4.99 a month or $49.99 a year (100 requests a day); Developer is $9.99 a month or $99.99 a year (1,000 a day). Cancel anytime in the App Store.
  • Codex: the CLI or the IDE extension.

Set it up in 4 steps

  1. Install HealthAPI and sync

    Get HealthAPI from the App Store, open it and allow Apple Health. Your history uploads, then new data keeps syncing.
  2. Add the server

    In a terminal, run codex mcp add healthapi --url https://healthapi.app/mcp. Codex saves it to ~/.codex/config.toml, sees that HealthAPI uses OAuth, and starts the sign-in straight away.
  3. Approve on your iPhone

    A HealthAPI page opens in your browser with a short code. Scan its QR code with your iPhone, or enter the code in HealthAPI under Connect, check it matches, and tap Approve. Codex prints “Successfully logged in.”
  4. Ask Codex

    Start codex, check /mcp lists healthapi, then ask for something that needs your data, such as “Use HealthAPI to get my last 30 nights of sleep.”
Shell
codex mcp add healthapi --url https://healthapi.app/mcp

The sign-in page labels Codex an unverified app and notes that it returns to a program on this computer (127.0.0.1). That is expected: HealthAPI can't check which program on your computer receives the answer. If you started it yourself and the codes match, approve it. Disconnect it later in the HealthAPI app under Settings, Connected apps.

In the IDE extension

Open the gear menu in the Codex panel, choose MCP servers, then Add server. Name it healthapi, choose Streamable HTTP, paste https://healthapi.app/mcp, save, and select Restart extension. The server list then shows HealthAPI as needing sign-in: select Authenticate and approve on your iPhone as above. A server added in the CLI shows up here too.

The config.toml entry

codex mcp add writes the first two lines to ~/.codex/config.toml. The third is optional: with "writes", Codex only asks before tools that aren't marked read only, and HealthAPI's are all read only, so it stops asking for them.

~/.codex/config.tomlTOML
[mcp_servers.healthapi]
url = "https://healthapi.app/mcp"
default_tools_approval_mode = "writes"

Each call still uses one of your daily requests, so leave the approval line out if you'd rather see every call. To use your API key instead of signing in, copy it in the app (Connect, then Other tools), put it in an environment variable, and name the variable. The key stays out of the file:

~/.codex/config.tomlTOML
[mcp_servers.healthapi]
url = "https://healthapi.app/mcp"
bearer_token_env_var = "HEALTHAPI_KEY"

What to build with it

  • A weekly report. “Use HealthAPI to get my last four weekly summaries and write a Markdown report comparing them, with the numbers in a table.”
  • A chart from real data. “Get 6 months of resting heart rate and HRV, save them as CSV, and write a small script that plots both.”
  • Tests with real fixtures. “Call get_daily_summary once and save the response as a test fixture for the parser you're writing.”
  • A question mid-task. “How much did I sleep this week compared with last?” works too.

What Codex builds should call the REST API with your key, not the MCP server; the JavaScript and Python guides show how. The MCP server page lists all eight tools and their inputs.

Questions

Why does the sign-in page say “Unverified app”?

Codex signs in through a program on your own computer, and HealthAPI can't prove from the outside which program that is. The name Codex comes from OpenAI's published client details, but the answer goes to 127.0.0.1, which any program could listen on. If you just ran the command yourself and the codes match, approve it.

The browser didn't open, or I closed it. What now?

Run codex mcp login healthapi to start again with a new code. Codex waits 5 minutes for the approval before it gives up.

Can I set it up in the IDE extension only?

Yes. Add it from the extension's MCP servers settings, as on this page. OpenAI's documentation says the CLI and the IDE extension share the same MCP configuration, so a server added in one shows up in the other.

How many requests does it use?

Each tool call is one request. A question usually takes one to three; a longer task may take more. Pro allows 100 a day and Developer 1,000, reset at 00:00 UTC.

Can Codex change my health data?

No. All eight tools are read only and marked that way, so Codex can tell. Nothing in Apple Health or HealthAPI changes. Disconnect it any time in the HealthAPI app under Settings, Connected apps.

The HealthAPI app icon

Your Health data, in Codex.

Get HealthAPI for iPhone, add the server, and approve it on your phone.