Draft an invoice from Codex
Create a Read and draft key for one business and put it in an environment variable. Add a [mcp_servers.billr] table with the Billr URL and bearer_token_env_var to ~/.codex/config.toml, or to .codex/config.toml in a trusted project, and restart Codex. A listed server is not proof the key works, so start with a read-only request, then ask for a draft from logged work. You review it, and sending is a separate action.
Written and reviewed by the Billr team. Published , last reviewed .
- Who this is for
- People running Codex in a terminal, the IDE extension, or the desktop app who want their own config, not a one-line command.
- Billr capabilities used
list_clientslist_unbilledcreate_invoice
What you need first
- A Billr account with at least one client, and the work you want to bill already logged. See Find unbilled work if the entries are not in Billr yet.
- On hosted Billr, a business with an active trial or subscription. Drafting is a write, and writes are refused for a business without one; reads keep working. Each account gets one 14-day trial from signup, and each business then needs its own subscription.
- Codex: the CLI, the IDE extension, or the ChatGPT desktop app. Codex's MCP documentation states that these share one MCP configuration.
- An API key with the Read and draft profile, limited to the business you invoice from, kept in an environment variable instead of a file.
Set it up
01Create a scoped key in Billr
In Billr, open Agents → API Keys and create a key. Pick the business under Business rather than leaving All businesses, and keep Read and draft (recommended) under Agent permissions. Copy the key before you close the dialog; it is shown once.
New keys expire 90 days after you create them, and the key list shows each key's expiry date. Read API keys and scopes before you grant anything broader.
02Put the key in an environment variable
Codex reads the token from the environment variable you name in the config, so the key never has to sit in a file. Do not paste it into a command line, where it is saved to your shell history. In bash or zsh, read it without echoing it:
read -rs BILLR_API_KEY && export BILLR_API_KEYPaste the key and press Enter. The variable lasts only for this terminal, and only processes started from it can see it. Start Codex from the same terminal.
03Add the server to config.toml
Codex stores MCP servers as a
[mcp_servers.<name>]table, by default in~/.codex/config.toml. Add:[mcp_servers.billr] url = "https://mcp.billr.cc" bearer_token_env_var = "BILLR_API_KEY"urlis the MCP endpoint, andbearer_token_env_varis the name of the variable holding the token, not the token itself. Never put the key itself in a config file.To enable Billr in one project only, put the same table in
.codex/config.tomlat the project root instead. Codex reads project config only in trusted projects. The IDE extension and the ChatGPT desktop app read the same configuration, so there is nothing to add again there.04Restart Codex and check the configuration
codex mcp listThis lists the servers Codex has configured. In the Codex TUI,
/mcpshows the active ones. Codex reads the config at startup, so restart a running session. Neither list proves the key works: Codex's documentation says that if no credential resolves, Codex can still connect without one. Billr then refuses every request with a 401, so the first tool call is the real test.05Make a read-only request first
Start by asking for reads only. A successful response confirms the key works and shows you which business and clients the session can see:
List my Billr clients and tell me what is still unbilled.Depending on your Codex settings, Codex may ask before it runs a Billr tool. That prompt is Codex's own control; keep it on. It does not change what the key may do in Billr.
06Then ask for the draft explicitly
With the work already logged and checked, ask for a draft built from that work only:
Draft the month-end invoice for Harbor & Lane from their unbilled time and expenses only, with no extra lines. Leave it as a draft and show me the business, client, currency and total.The draft is built from the records, so each line carries the recorded amount. Do not ask for extra hand-written lines in the same request: when
create_invoicereceives time or expense ids, it writes lines from those records only and drops anyline_itemssent with them.
Worked example
Fictional account, field names as returned by the server
You say
Draft the month-end invoice for Harbor & Lane from their unbilled time and expenses only, with no extra lines. Leave it as a draft and show me the business, client, currency and total.
Your agent calls
list_unbilled { "client_id": "9f2a4d18-3b7c-4a6e-8f0d-1c5b2e9a7d44" }create_invoice { "request_id": "1f5a7c93-2b64-4d08-9e31-6c0a4b7d2f85", "client_name": "Harbor & Lane", "issue_date": "2026-09-30", "time_entry_ids": [ "3f6c1a44-5b2d-4e71-9c08-7a1d3f5b9e22", "c2b7e4d9-8f30-4a51-9e6d-3b5a1c7f0d92", "9a2d0b71-6c34-4f52-8e19-2b7c4d0a6f31" ], "expense_ids": [ "d41b8e93-2a70-4c15-9b6f-5e8a1c3d7f08" ] }
Illustrative response for a fictional account, abridged. It is not a recorded session; source lines keep the shape the server writes.
{
"summary": "Drafted INV-1148 for Harbor & Lane: $1,060.00 Source work was priced and linked atomically.",
"invoice": {
"id": "b7c1e5a0-51de-4b2c-9f0a-8f2c4d1e6a33",
"business_id": "e4c7a2d9-5b13-4f86-9a20-7d3e1b6c8f05",
"client_id": "9f2a4d18-3b7c-4a6e-8f0d-1c5b2e9a7d44",
"invoice_number": "INV-1148",
"status": "draft",
"issue_date": "2026-09-30",
"due_date": "2026-10-14",
"currency": "USD",
"total": 1060,
"balance_due": 1060,
"line_items": [
{
"description": "Schema markup fixes (5400 seconds)",
"quantity": 1,
"rate": 225,
"amount": 225
},
{
"description": "Content refresh (16200 seconds)",
"quantity": 1,
"rate": 675,
"amount": 675
},
{
"description": "Analytics audit (2700 seconds)",
"quantity": 1,
"rate": 112.5,
"amount": 112.5
},
{
"description": "Client lunch",
"quantity": 1,
"rate": 47.5,
"amount": 47.5
}
]
},
"linked_time_entry_ids": [
"3f6c1a44-5b2d-4e71-9c08-7a1d3f5b9e22",
"c2b7e4d9-8f30-4a51-9e6d-3b5a1c7f0d92",
"9a2d0b71-6c34-4f52-8e19-2b7c4d0a6f31"
],
"linked_expense_ids": [
"d41b8e93-2a70-4c15-9b6f-5e8a1c3d7f08"
],
"public_url": "https://billr.cc/i/8pLw2Xk7Qa",
"pdf_url": "https://billr.cc/api/public/invoices/8pLw2Xk7Qa/pdf",
"app_url": "https://billr.cc/invoices/b7c1e5a0-51de-4b2c-9f0a-8f2c4d1e6a33"
}Review the draft, then send it separately
Open the draft from app_url and check four things yourself: the client, the business it was created under (business_id), the currency and the amount. Each linked entry is now attached to this draft, so compare the lines with the unbilled list you approved.
Sending is a separate action. You can send from Billr, or from an agent whose key has the Billing or Full profile. With a Read and draft key, send_invoice is not offered to the session at all, and approving a Codex tool prompt does not add that permission. With a key that can send, an approved send_invoice call emails the client immediately, and Billr asks for no further confirmation. Task pricing and task invoice approval have separate mandatory human approval steps in Billr.
What this flow does not do
- The invoice is a draft. Nothing reaches your client until someone sends it.
- The billed amounts come from the logged work. Entries logged without a rate cannot be attached to an invoice at all; the server rejects them with
Time must be unbilled, billable, priced and assigned to this client. - Time can go only on an invoice in the business's default currency, and each expense only on an invoice in its own currency. Nothing is converted.
- Billing a client for the AI usage behind the work is a separate decision. See How to bill clients for AI usage.
- Billr also supports browser sign-in for MCP clients, set up from Connect your agent. This guide covers only the scoped API key.
Troubleshooting
- The billr server does not appear in codex mcp list
- Check the table name and the file you edited. Codex reads ~/.codex/config.toml, or .codex/config.toml in a trusted project. TOML is case-sensitive, and the header must be [mcp_servers.billr].
- Billr is listed, but the first request fails with 401
- Billr's 401 says "Missing or invalid access token" when no valid key arrives. First confirm the variable is set without printing it, by running test -n "$BILLR_API_KEY" && echo "BILLR_API_KEY is set" || echo "BILLR_API_KEY is unset" in the shell that starts Codex. If it is set, check the key's expiry in Agents → API Keys; an expired or revoked key needs a new key and a new value in the variable. The hosted endpoint is https://mcp.billr.cc.
- It works from the CLI but not in the IDE extension or desktop app
- Codex reads BILLR_API_KEY from the environment of the process running it. An app opened from your desktop may not have variables you exported in a terminal. Start it from an environment where BILLR_API_KEY is set, or use the CLI from the terminal where you set it.
- It stopped working in a new terminal or after a restart
- A variable set with read and export lasts only for that terminal. Set it again before starting Codex, or load it from your own secret manager.
- send_invoice, payments or delete tools are missing
- Billr only offers the tools the key allows. Read and draft has no send, payment or delete tools. Keep it that way for this guide; create a separate Billing key only when you decide an agent should send.
- A draft is refused with plan_required
- This business has no active hosted trial or subscription. Reads still work; drafting and other writes do not. Check the business in Billing.
- "Multiple businesses in scope … pass business_id"
- The key was created for All businesses and you belong to more than one. Create a key for the one business you invoice from, or tell the agent which business_id to use.
- The agent created two drafts for one request
- Retries must reuse the same request_id and the same input. create_invoice returns the original draft when the id matches, and creates a new invoice when it does not.
Sources
Reviewed 2026-10-15 against Billr's own tool implementations and the client documentation linked above.
Read next
A hosted account gives you the MCP endpoint this guide points at, with one 14-day trial from signup; each business then needs its own subscription. A self-hosted install serves the same tools from its own origin.
Create an account