SShortSingh.
Back to feed

Tracking Token Costs Across Multiple AI Providers Behind One API Key

0
·7 views

Using a single API key across OpenAI, Claude, and Gemini does not automatically produce comparable cost and usage data. The article argues that teams should instrument the full request lifecycle and record dimensions that explain the work performed, rather than relying on one aggregate cost figure. It proposes a three-level identity scheme (request, attempt, and span) so that retries, streaming output, and tool calls can be distinguished and correctly counted. Each telemetry event should carry explicit, consistently defined fields such as model, operation, status, timing, and input and output units, with estimated and provider-confirmed values labeled separately. The author also notes that retries can make dashboards misleading, recommending that delivered work and total performed work be tracked as separate totals.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Browser-based mail converter embeds remote images in PDFs, flagging blocked ones honestly

A developer added a save-as-PDF feature to a browser mail viewer that processes everything locally using a Web Worker and pdf-lib. Images embedded in the message were straightforward to include, but remotely linked images raised privacy and technical challenges. To avoid tracking, requests omit cookies and referrer data, skip tiny tracking pixels, and refuse private-network addresses. Because many image hosts do not allow cross-origin reads, some pictures cannot be fetched, so the PDF shows labeled placeholder boxes explaining the reason instead of blank gaps. A sample of popular hosts found that roughly two-thirds sent the needed CORS header, indicating that many newsletter images cannot be embedded client-side.

0
ProgrammingDEV Community ·

Why Honest Competitor Comparison Pages Build More Trust Than Rival-Bashing

Many 'X alternative' pages target competitors' search traffic with invented weaknesses, outdated screenshots, and tables that always favor the author. Such pages erode merchant trust in the format as a whole, including among vendors who write fair comparisons. The author argues for acknowledging rivals' genuine strengths, such as a longer track record, and comparing on structural, verifiable differences like pricing model and how retries are handled. Claims should be dated and publicly corrected as the market changes. The author cites their own Churn Buster alternative page, which contrasts a flat fee with percentage-of-recovery pricing and is candid that their product is only six weeks old against a competitor's twelve years.

0
ProgrammingDEV Community ·

Payment Failures Behave Differently Across Subscription Platforms

A failed payment on Stripe is a documented event with a code, webhook, and clear record, whereas the same failure within a subscription platform's billing layer follows that platform's own terminology, timing, and retry rules. Treating these as a single problem with one recovery approach can lead to double charges or waiting out native schedules that fail to recover revenue. The key differences are mechanical: who owns the payment attempt, what the platform's default retry logic does without intervention, and where the customer's card information is stored and updated. The author argues recovery tools must address these questions separately for each platform. Swipe Again says it prefers publishing separate, platform-specific guides, such as its Recharge dunning guide versus its Stripe Billing guide.

0
ProgrammingDEV Community ·

Why Subscription Grace Periods Are a Deliberate Product Choice

The article argues that the interval between a failed subscription payment and cancellation is a deliberate design decision, whether or not companies acknowledge it. A window that is too short can lose customers over a temporary empty balance, while one that is too long gives service away to people who have effectively left. The author says the length reflects how much a business trusts subscribers and how it times its messages around payday. The best grace periods go unnoticed because the payment resolves within them, while the worst surprise customers with a cancellation notice. The piece also notes that percentage-based recovery fees make long windows costly, which it presents as an argument for flat-fee pricing.