Skip to content

devlog/token-math/separate-project-keys-cleaner-token-spend-722.md

Separate Project Keys, Cleaner Token Spend

Separate Project Keys, Cleaner Token Spend

The fastest way to lose track of AI spend is to export one API key in your shell profile and forget about it. Three repositories, two coding agents, and a weekend experiment later, the bill tells you how much you spent, but not which project deserved it. Separate keys turn that shared expense into something you can attribute, investigate, and eventually optimize.

Fluxo gives you one base URL, https://api.fluxorelay.com, and a key that can access Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok, and more. That means you do not need separate provider credentials for each model family. For accounting, though, deliberately use separate keys for separate projects.

Make Each Key Represent One Cost Boundary

Start with one key per repository or deployable service, not one key per developer. A developer moves between projects; the accounting boundary should stay put. If a monorepo contains independently funded services, split keys along those service boundaries instead.

  • Record the project, environment, owner, and rotation date beside each key identifier.
  • Separate production traffic from development experiments when their budgets have different owners.
  • Give shared automation its own key instead of borrowing somebody's local credentials.
  • Keep a dated mapping when rotating keys so historical attribution remains intact.

This mapping can live in a small internal registry. Store identifiers or fingerprints there, never the full credentials. Avoid splitting every script into its own accounting unit until you actually need that granularity.

Load Project Credentials Without Polluting Your Shell

Keep credentials out of your global shell startup files. Use an ignored environment file, a directory-aware environment loader, or a wrapper that retrieves the project secret from your secret manager. Commit a template containing variable names, not values.

For an OpenAI SDK client, explicitly configure the base URL and inject the project's key at process startup. Fluxo also works with Claude Code, Codex, and Gemini CLI, but check each tool's configuration mechanism rather than assuming they all read identical environment variables.

Be especially careful with long-running editor terminals, agent sessions, and terminal multiplexers. Changing directories does not necessarily replace an already running process's credentials. Restart the client after switching projects, and expose a non-secret project label in your launcher so mistakes are visible.

Capture Usage Before Aggregating Project Costs

Separate keys establish ownership; usage records explain the spend. Capture timestamps, project labels, model names, available request identifiers, and returned usage fields. For streaming clients, verify whether your integration actually receives final usage metadata. Treat missing usage as unknown, not zero.

If you compare Claude Sonnet 5.5 with GPT-6.1 Sol, retain the model dimension even when both requests use the same project key. Otherwise, a model switch can look like an unexplained regression in project efficiency.

Account for Cache Reads and Writes Explicitly

Fluxo bills per real token, including cache reads and writes, with no monthly fee. A single undifferentiated token counter is therefore insufficient for accurate cost attribution. Preserve the billing categories exposed by your usage source and apply the relevant rates.

Check field semantics before summing anything. Cached tokens may already be included in another total; adding them again can double-count usage. Compare cold and warm runs separately, especially when an agent repeatedly sends repository context. Stable prompts may change cache behavior, so measure rather than assuming every repeated request costs the same.

Reconcile Local Telemetry Against Billed Usage

Use local logs for fast feedback and the billing record as the authority for charges. Reconcile by project key and a consistent time window. Time zones, delayed reporting, interrupted streams, and retries can all create differences between your client logs and billed activity.

For automation, enforce request or concurrency limits in your own runner unless you have verified equivalent server-side controls. Revoking a key is an incident response, not a substitute for a budget guardrail.

Keep Project Spend Separate From Referral Income

Users earn a referral share when people they invite pay. Track that income separately from gross project usage so it does not hide an expensive workflow. If you want to try this setup, create a Fluxo account and start with separate keys for two repositories. The first useful result is simply knowing which terminal session owns the bill.

Next in the buffer

Sign up in a minute and get credit to try every model mentioned here. Sign up →