Skip to content

OpenAI cost per tenant — one key, tagged requests, a P&L

One OpenAI key can serve every customer. The Costs API can group by api_key. That is still your key, not their tenant_id. Tag the request. Then read a customer P&L.

Engineers who ask for OpenAI cost per tenant usually share one key. Opening a project or a key per customer does not scale. OpenAI’s Costs API group_by=api_key answers “which of our keys.” It does not answer “which row in our tenants table.”

CostSlice keeps that one key. You send x-cs-tenant — an opaque id, never an email — plus x-cs-key. The customer P&L is cost versus what they pay.

api.costslice.com/v1

from openai import OpenAI
import os

client = OpenAI(
    base_url="https://api.costslice.com/v1",
    api_key=os.environ["OPENAI_API_KEY"],
    default_headers={
        "x-cs-key": os.environ["COSTSLICE_KEY"],
        "x-cs-tenant": tenant_id,       # opaque id, never an email
        "x-cs-feature": "support-copilot",
        "x-cs-env": "prod",
    },
)

Keys stay in your product’s environment variables. We never store the OpenAI API key. Quickstart. Allocation: allocate the OpenAI bill. Finance noun: OpenAI cost P&L.

Worked example: the sample tenant acme-health is one opaque id on clinical-summary. Plan $2,400. LLM cost $4,812. Margin −101%. That is cost per tenant, not cost per API key. See the sample P&L.

Starter is free. No credit card. Operator: Media Yard LLC, PO Box 73, Pennsauken, NJ 08110. hello@costslice.com

Questions

Does OpenAI show cost per tenant?
No. The Costs API can group by API key or project. That is still your key, not the tenant_id in your product. CostSlice is the tagged customer P&L.
Do I need one API key per customer?
No. Keep one OpenAI API key. Send x-cs-tenant on the request. We never store the OpenAI API key.
What if I forget x-cs-tenant?
The completion still returns. We record untagged so you can fix the header.
Do you store prompts?
No. We store usage metadata. Prompt and completion bodies are not written to disk.