SShortSingh.
Back to feed

Five SQL Charts That Make LLM API Costs Readable for Finance, Eng, and Product

0
·1 views

A practical guide published on DEV Community outlines how to build an effective LLM cost dashboard using just five charts, each designed to answer a specific question from finance, engineering, or product teams. The approach avoids two common pitfalls: oversimplified single-number dashboards and bloated multi-panel displays that go unread. All queries run against a production LLM request log table, with a strict filter excluding eval and staging environments to prevent data contamination. Key panels include a daily spend trend with month-to-date totals and end-of-month projections, plus a stacked breakdown by feature, model, or tenant using a top-N grouping with an 'other' bucket. The guide emphasizes reusable, parameterized queries so the same SQL can answer different business questions without maintaining redundant code.

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 ·

How to Handle LLM API Error Messages Without Breaking Your Integration

Large language model inference APIs return a consistent set of error responses, but most developers handle them with a blanket retry strategy that can worsen certain failures and obscure others. Errors from providers like OpenAI and Anthropic include both an HTTP status code and a structured JSON body, and the type or code field within that body is the most actionable piece of information. The core principle for building a correct retry policy is determining whether the identical request will succeed later — capacity issues are retryable, validation or auth failures are not, and billing or regional restrictions require human intervention. Branching logic should rely on status codes and type fields rather than error message text, since prose messages can be reworded or localized without notice. Common status codes such as 400, 401, 403, and 422 each signal distinct non-retryable conditions, and looping retries on these can exhaust timeout budgets or trigger self-inflicted outages during events like key rotations.

0
ProgrammingDEV Community ·

Why Language Models Fail at Date and Time Reasoning — and How to Fix It

Language models have no internal clock or timezone awareness, meaning they silently infer the current date from training data patterns rather than reality, often skewing toward their training cutoff. Without an explicit timestamp in the system prompt, any calculation involving 'next Friday' or 'in 90 days' is computed from an unverified guess, producing confident but potentially wrong dates. Arithmetic across month boundaries, leap years, DST transitions, and timezone offsets compounds the problem, as models routinely conflate fixed UTC offsets with full IANA timezone rules. Research benchmarks including TimeQA, TempReason, and Google's Test of Time consistently show that model accuracy on temporal tasks depends more on how facts are structured and presented than on the inherent difficulty of the question. The simplest mitigation is injecting a complete, unambiguous timestamp — including date, time, UTC offset, IANA zone name, and weekday — into every system prompt where time-sensitive reasoning is required.

0
ProgrammingDEV Community ·

Why LLM-Driven Data Analysis Can Quietly Produce Wrong Results

Large language models can write and execute data analysis code, but errors in the code, statistical methods, or interpretation can each produce misleading results without triggering any visible warning. Silent data loss from dropped missing values, mishandled joins, or type coercion errors can alter an analysis entirely while the code continues to run cleanly. Statistical pitfalls such as violated independence assumptions, multiple comparisons without correction, and bad covariate choices can yield false or distorted findings that the model presents with apparent confidence. Unlike a human analyst, an LLM typically lacks familiarity with the specific dataset, making it less likely to catch context-dependent anomalies. Experts suggest that routinely printing row counts at each transformation step is one of the most effective ways to surface many of these hidden data integrity issues.

0
ProgrammingDEV Community ·

Why AI Confidence Scores Don't Reliably Detect Hallucinations

A language model is considered well-calibrated if its stated confidence levels match its actual accuracy rates — for instance, predictions made at 70% confidence should be correct roughly 70% of the time. Researchers, notably Guo et al. in a 2017 paper, established that modern neural networks trained for high accuracy tend to be significantly overconfident, though a technique called temperature scaling can largely correct this without affecting accuracy. Calibration is distinct from discrimination, meaning a model can be perfectly calibrated yet still be practically useless if it simply predicts average base rates. If language models were reliably self-calibrated, hallucination detection would be straightforward — low-confidence responses could be flagged and routed to humans or external search tools. A 2022 Anthropic study by Kadavath et al. found that large models show reasonable calibration on multiple-choice tasks, but this does not fully translate to open-ended generation, which is where hallucination detection remains an unsolved challenge.