Skip to content

Native inference billing#433

Open
Ken Jiang (knjiang) wants to merge 4 commits intomainfrom
04-01-native_inference_billing
Open

Native inference billing#433
Ken Jiang (knjiang) wants to merge 4 commits intomainfrom
04-01-native_inference_billing

Conversation

@knjiang
Copy link
Copy Markdown
Contributor

@knjiang Ken Jiang (knjiang) commented Apr 1, 2026

This starts emitting billing events for models with the prefix of brain-*

slack thread has my QA testing.

TODO: wire up embeddings

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ai-proxy Ready Ready Preview, Comment Apr 2, 2026 5:41pm

Request Review

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@knjiang Ken Jiang (knjiang) force-pushed the 04-01-native_inference_billing branch from 93e0bb7 to 4f147d0 Compare April 1, 2026 23:53
# You should not need to edit this
BRAINTRUST_APP_URL = "https://www.braintrust.dev"
METRICS_LICENSE_KEY="<YOUR_METRICS_LICENSE_KEY>"
BILLING_TELEMETRY_URL="https://api.braintrust.dev/billing/telemetry/ingest"
Copy link
Copy Markdown
Contributor Author

@knjiang Ken Jiang (knjiang) Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this how u configure the proxy?

@knjiang Ken Jiang (knjiang) changed the title native inference billing Native inference billing Apr 2, 2026
@knjiang Ken Jiang (knjiang) force-pushed the 04-01-native_inference_billing branch from 9a9655a to b8426af Compare April 2, 2026 00:12
@knjiang Ken Jiang (knjiang) marked this pull request as ready for review April 2, 2026 00:12
Comment on lines +6 to +7
function isBrainModel(model: string): boolean {
return model.startsWith("brain-");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i added this guard after testing with gpt-5-mini

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8426af769

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "Codex (@codex) review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "Codex (@codex) address that feedback".

let spanId: string | undefined;
let spanExport: string | undefined;
let billingOrgId: string | undefined;
const orgName = request.headers.get(ORG_NAME_HEADER) ?? undefined;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Resolve billing org using routed org context

Billing org lookup is keyed only by ORG_NAME_HEADER, but proxy routing can override org from the URL path (/btorg/{org}/... in packages/proxy/src/proxy.ts). In that case, billingOrgId is resolved for the key’s default/header org while the request is actually executed under the path org, so telemetry can be attributed to the wrong external_customer_id and corrupt billing for multi-org keys.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm i think this is fine? how do u make a mutli-org api key in braintrust today?

Comment on lines +123 to +126
const apiKey =
parseAuthHeader({
authorization: request.headers.get("authorization") ?? undefined,
}) ?? undefined;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Accept x-api-key when deriving billing org id

This API key extraction only reads Authorization, but proxyV1 also supports x-api-key authentication. For clients that authenticate via x-api-key (common in Anthropic-compatible flows), billingOrgId remains unset and buildPayloadEvent skips the telemetry because org_id is missing, so native inference usage is silently not billed.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine, we'll get warning logs if we can't build the payload without org id.

i just moved the logic out of BT_PARENT conditional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant