Skip to content

Cookbook

Bill your own customers

For agencies and software houses: tag each request with your customer, then get each customer's usage and cost for the month, as a CSV or from the API.

Last updated: 2026-10-26

If you build on AI Tokens for several customers of yours, one account and one key are enough: tell us, on each request, which customer it is for, and at the end of the month read each customer's requests, tokens and cost.

1. Tag each request

Send your own id for the customer in user, the standard OpenAI field. Any string up to 256 characters: a customer code, a VAT number, a project. We keep it on the usage line and do not send it to the model.

python
from openai import OpenAI

client = OpenAI(base_url="https://api.ai-tokens.it/v1", api_key=API_KEY)

response = client.chat.completions.create(
    model="qwen3.8-27b",
    messages=[{"role": "user", "content": "Riassumi questo contratto…"}],
    user="rossi-srl",
)

The same field works on the Responses API and on embeddings; OpenAI's newer safety_identifier is read the same way. A request without it counts for the client "".

If each customer of yours needs its own monthly limit, give each one its own key instead, and group by key below.

2. At the end of the month

From the dashboard: the Usage page, period «last month», CSV by client: one line per client and model, with requests, input tokens (and how many of them came from the engine's cache), output tokens and cost.

From the API, for your own billing run:

bash
curl "https://api.ai-tokens.it/v1/usage?period=last-month&group_by=client,model&format=csv" \
  -H "Authorization: Bearer $API_KEY" -o usage.csv
text
client,model,requests,input_tokens,cached_tokens,output_tokens,cost
rossi-srl,qwen3.8-27b,1820,2410334,1928267,611208,0.426713
bianchi-spa,qwen3.8-27b,312,402118,321694,98114,0.071226

Without format=csv the answer is JSON, with a total. Other periods, a single client and the other groupings are in Account and usage.

Good to know

  • The cost is ours to you, excluding VAT, in the currency of your account: what you charge your customer on top is yours to decide.
  • The months are Swiss time: a request at 00:30 on the 1st belongs to the new month.
  • The id is yours. Do not put personal data in it: a code is enough, and it is what you will read in the file.

Search the docs

Type to search…