How do I see how many tokens each API key and each AI model uses?

Create one key per app or environment and check usage per key, per model and per request in the Dongee AI Router client area. For per-function detail, log the usage object in your own logs.

To track token usage per API key, create a separate key for each app or environment and check the Dongee AI Router client area, which shows usage per model, per key and per request. Dongee AI Router is Dongee's prepaid gateway to AI models. For per-function detail, log the usage object when responses include it.

This guide helps you answer one specific question: which app, environment or function is using up your AI credit, and with which model? It takes five short steps.

Step 1: use a separate key per app or environment

Usage per key is only useful if each key has a single owner. If production, testing and three clients share the same key, you will see a total, but you won't know who generated it.

  • One key for production and another for testing.
  • One key per client, if you build projects for others.
  • One key per app or automation (for example, an n8n workflow or a Node.js backend).

In AI Router you can create as many keys as you need per account, so keeping them separate is easy. If you also want each key to use only certain models, follow the guide to restrict an API key to certain AI models. Always keep keys on the server, never in the browser.

Step 2: check usage in the client area

The Dongee AI Router client area gives you three views of usage:

  • Per model: which models account for most of the spend.
  • Per key: which app, environment or client uses the most.
  • Per-request detail: the billing data for each call, useful for spotting spikes or unusual requests.

If you did step 1 properly, comparing “key” and “model” can already tell you, for example, that your testing environment is using a more expensive model than it needs.

Step 3: log usage in your app too

The client area shows spend per key, but it doesn't know which function in your code made each request. For that you need your own logs. In the OpenAI standard, many responses include a usage object with prompt_tokens, completion_tokens and total_tokens. If the response includes it, store it along with the environment, the function and the model. If it's missing, your code should keep working the same way.

Here's an example in Node.js (ESM) with the OpenAI SDK:

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: process.env.AI_ROUTER_BASE_URL,
  apiKey: process.env.AI_ROUTER_API_KEY,
});

const model = process.env.AI_MODEL;
const entorno = process.env.APP_ENV ?? "pruebas";

export async function preguntar(texto, funcion) {
  const respuesta = await client.chat.completions.create({
    model,
    messages: [{ role: "user", content: texto }],
  });

  // Only log when the response includes usage
  if (respuesta.usage) {
    console.log(JSON.stringify({
      fecha: new Date().toISOString(),
      entorno,
      funcion,
      modelo: model,
      prompt_tokens: respuesta.usage.prompt_tokens,
      completion_tokens: respuesta.usage.completion_tokens,
      total_tokens: respuesta.usage.total_tokens,
    }));
  }

  return respuesta.choices[0].message.content;
}

Never write the key to your logs. The environment name is enough. If you haven't set up the SDK yet, see how to use the OpenAI SDK in Node.js with a compatible API. The base URL and the model list are in your client area.

Step 4: compare and act

Once you have the data, look for patterns like these:

  1. An expensive model doing easy tasks (classifying, summarizing short texts, extracting fields). Switch that function to a lighter model.
  2. A testing environment spending almost as much as production. Check for loops, retries or automated tests that call the AI when they don't need to.
  3. Requests with lots of prompt_tokens. Trim the context you send with each call.

You program the routing between models yourself. To decide which model to use for each task, follow the guide to optimize token usage with AI routers.

Step 5: control spending

AI Router is prepaid, starting at 3 USD, with no monthly fee. If your credit runs out, requests stop and you don't go into debt. Combined with one key per app, that is your main control: you know the most you can spend and who is spending it.

Where to find each data point

Question you want to answerWhere to look
Which app, environment or client spends the most?Client area, usage per key
Which model accounts for most of the spend?Client area, usage per model
Was there an unusual request or a spike?Client area, per-request detail
Which function in my code uses the most tokens?Your logs, with usage when the response includes it

Privacy: AI Router does not store the content of your conversations. It only keeps the billing data for each request.

When the client area is enough and when it isn't

The client area is enough if you have only a few apps, use one key per app or environment and just need to know how much each one spends and with which model.

Consider adding your own logs or a self-hosted gateway such as LiteLLM if you need to attribute spend to functions or end users within the same app, match it against your business metrics or bring several providers together in one place. AI Router can sit behind a gateway like that. The trade-off is that you have to maintain that gateway yourself. Also, don't expect Dongee to provide automatic fallback between models. That logic belongs in your code or your gateway.

Frequently asked questions

Can I see the text of requests in the client area?

No. AI Router does not store the content of conversations, only the billing data for each request. If you need the text for debugging, store it in your own systems under your own privacy rules.

Are there spending alerts?

The main control is prepaid credit: when it runs out, requests stop and you don't go into debt. Combine it with one key per app so you always know who is using it.

How much does each token cost?

This guide doesn't cover rates. You can see what each key and each model spends in the client area's usage views. For current rates, check the Dongee AI Router page or contact 24/7 human support in your language (the platform translates on the fly). Support also answers questions before you sign up.

Can I see usage for a single function in my app?

Not from the client area, which shows usage per key and per model. To see it per function, log it as shown in step 3 or use a separate key for that function.

Do I need to be a Dongee customer to use AI Router?

Yes. You activate it from the client area. New accounts get a welcome credit so they can start testing.

Summary

Use one key per app or environment and check usage per key and per model in the client area. If you need more detail, store usage in your logs. That way you'll know who is spending your AI credit and can decide which model to change.

Comenta lo que quieras

Unete a la charla
Solo ingresa tu email