Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat(llm-pricing): add Unpriced Models tab with billing-model mapping [6/6] (#11813)

Gaurav Tewari2704317c6ae9
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.module.scss b/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.module.scss
index ece63fd7db..5ea09cc779 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.module.scss
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.module.scss
@@ -3,3 +3,13 @@
flex-direction: column;
gap: var(--spacing-8);
}
+
+.tabLabel {
+ display: inline-flex;
+ align-items: center;
+ gap: 8px;
+}
+
+.tabBadge {
+ margin: 0;
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.tsx b/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.tsx
index f774591e26..4e230ddd31 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.tsx
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/LLMObservabilityModelPricing.tsx
@@ -1,30 +1,58 @@
+import { Badge } from '@signozhq/ui/badge';
import { Tabs } from '@signozhq/ui/tabs';
+import { useListUnmappedLLMModels } from 'api/generated/services/llmpricingrules';
+import { parseAsStringEnum, useQueryState } from 'nuqs';
-import ModelCostTabPanel from './ModelCostTabPanel';
+import { MODEL_COSTS_TAB, TAB_KEY, UNPRICED_MODELS_TAB } from './constants';
import styles from './LLMObservabilityModelPricing.module.scss';
+import ModelCostTabPanel from './ModelCostTabPanel';
+import UnpricedModelsTab from './UnpricedModelsTab';
function LLMObservabilityModelPricing(): JSX.Element {
+ const [activeTab, setActiveTab] = useQueryState(
+ TAB_KEY,
+ parseAsStringEnum([MODEL_COSTS_TAB, UNPRICED_MODELS_TAB]).withDefault(
+ MODEL_COSTS_TAB,
+ ),
+ );
+
+ // Count powers the tab badge; deduped with the tab's own fetch by react-query.
+ const { data } = useListUnmappedLLMModels();
+ const unpricedCount = data?.data?.items?.length ?? 0;
+
return (
<div
className={styles.llmObservabilityModelPricing}
data-testid="llm-observability-model-pricing-page"
>
<Tabs
- // Model costs is the only enabled tab for now, so default to it. When
- // the unpriced-models tab lands in a later PR.
- defaultValue="model-costs"
+ value={activeTab}
+ onChange={(key): void => {
+ void setActiveTab(key as typeof activeTab);
+ }}
items={[
{
- key: 'model-costs',
+ key: MODEL_COSTS_TAB,
label: 'Model costs',
children: <ModelCostTabPanel />,
},
{
- // Unpriced-models tab lands in a later PR.
- key: 'unpriced-models',
- label: 'Unpriced models',
- disabled: true,
- children: null,
+ key: UNPRICED_MODELS_TAB,
+ label: (
+ <span className={styles.tabLabel}>
+ Unpriced models
+ {unpricedCount > 0 && (
+ <Badge
+ variant="default"
+ className={styles.tabBadge}
+ data-testid="unpriced-models-count"
+ >
+ {unpricedCount}
+ </Badge>
+ )}
+ </span>
+ ),
+ children: <UnpricedModelsTab />,
},
]}
/>
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/hooks/useModelCostDrawer.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/hooks/useModelCostDrawer.ts
index 2586b3387a..613dbcfdfd 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/hooks/useModelCostDrawer.ts
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/hooks/useModelCostDrawer.ts
@@ -3,6 +3,7 @@ import { toast } from '@signozhq/ui/sonner';
import { useQueryClient } from 'react-query';
import {
getListLLMPricingRulesQueryKey,
+ getListUnmappedLLMModelsQueryKey,
useCreateOrUpdateLLMPricingRules,
} from 'api/generated/services/llmpricingrules';
@@ -10,9 +11,16 @@ import {
EMPTY_DRAFT,
TOAST_MODEL_COST_ADDED,
TOAST_MODEL_COST_UPDATED,
-} from '../../../../constants';
-import type { DrawerDraft, DrawerMode, PricingRule } from '../../../../types';
-import { buildRulePayload, draftFromRule } from '../../../../utils';
+} from 'container/LLMObservability/Settings/ModelPricing/constants';
+import type {
+ DrawerDraft,
+ DrawerMode,
+ PricingRule,
+} from 'container/LLMObservability/Settings/ModelPricing/types';
+import {
+ buildRulePayload,
+ draftFromRule,
+} from 'container/LLMObservability/Settings/ModelPricing/utils';
interface UseModelCostDrawerResult {
isOpen: boolean;
@@ -38,17 +46,26 @@ export function useModelCostDrawer(): UseModelCostDrawerResult {
const { mutateAsync: createOrUpdate, isLoading: isSaving } =
useCreateOrUpdateLLMPricingRules();
+ // Adding pricing can also resolve a model that was showing up as unpriced, so
+ // refresh the unmapped list (and its tab-badge count) alongside the rules list.
const invalidateList = useCallback(async (): Promise<void> => {
- await queryClient.invalidateQueries({
- queryKey: getListLLMPricingRulesQueryKey(),
- });
+ await Promise.all([
+ queryClient.invalidateQueries({
+ queryKey: getListLLMPricingRulesQueryKey(),
+ }),
+ queryClient.invalidateQueries({
+ queryKey: getListUnmappedLLMModelsQueryKey(),
+ }),
+ ]);
}, [queryClient]);
- const openForAdd = useCallback((): void => {
+ // prefillModelName seeds the billing model ID when adding from an unpriced
+ // model row, so the user only has to fill in pricing.
+ const openForAdd = useCallback((prefillModelName?: string): void => {
setMode('add');
setInitialDraft({
...EMPTY_DRAFT,
- modelName: '',
+ modelName: prefillModelName ?? '',
patterns: [],
});
setSelectedRuleId(null);
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/shared.module.scss b/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/shared.module.scss
index 51677e14e9..c0d637caad 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/shared.module.scss
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/ModelCostTabPanel/components/ModelCostDrawer/shared.module.scss
@@ -25,7 +25,6 @@
.drawerSurface {
padding: var(--spacing-7);
border-radius: 6px;
- background: var(--l2-background);
border: 1px solid var(--l2-border);
}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/UnpricedModelsTab.module.scss b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/UnpricedModelsTab.module.scss
new file mode 100644
index 0000000000..b5635a7fab
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/UnpricedModelsTab.module.scss
@@ -0,0 +1,27 @@
+.unpricedModelsTab {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-8);
+}
+
+.banner {
+ display: flex;
+ align-items: flex-start;
+ gap: var(--spacing-5);
+ padding: var(--spacing-6) var(--spacing-8);
+ border-radius: var(--radius-2);
+ border: 1px solid color-mix(in srgb, var(--bg-amber-400) 30%, transparent);
+ background: color-mix(in srgb, var(--bg-amber-400) 8%, transparent);
+ color: var(--bg-amber-300, var(--bg-amber-400));
+}
+
+.bannerIcon {
+ flex-shrink: 0;
+ margin-top: var(--spacing-1);
+}
+
+.error {
+ padding: var(--spacing-6) var(--spacing-8);
+ border-radius: var(--radius-2);
+ background: color-mix(in srgb, var(--bg-cherry-400) 8%, transparent);
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/UnpricedModelsTab.tsx b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/UnpricedModelsTab.tsx
new file mode 100644
index 0000000000..ccb7fa9f09
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/UnpricedModelsTab.tsx
@@ -0,0 +1,132 @@
+import { useCallback, useEffect, useMemo } from 'react';
+import { Typography } from '@signozhq/ui/typography';
+import { TriangleAlert } from '@signozhq/icons';
+import { useListUnmappedLLMModels } from 'api/generated/services/llmpricingrules';
+import useComponentPermission from 'hooks/useComponentPermission';
+import { useAppContext } from 'providers/App/App';
+
+import styles from './UnpricedModelsTab.module.scss';
+import ModelCostDrawer, {
+ useModelCostDrawer,
+} from '../ModelCostTabPanel/components/ModelCostDrawer';
+import type { PricingRule, UnpricedModel } from '../types';
+import MapConfirmDialog from './components/MapConfirmDialog';
+import type { UnpricedColumnsConfig } from './components/UnpricedModelsTable/TableConfig';
+import UnpricedModelsTable from './components/UnpricedModelsTable';
+import { useUnpricedModelMapping } from './hooks/useUnpricedModelMapping';
+import { usePendingMappingStore } from './usePendingMappingStore';
+
+function UnpricedModelsTab(): JSX.Element {
+ const { data, isLoading, isError } = useListUnmappedLLMModels();
+
+ const { user } = useAppContext();
+ const [canManagePricing] = useComponentPermission(
+ ['manage_llm_pricing'],
+ user.role,
+ );
+
+ const models: UnpricedModel[] = useMemo(() => data?.data?.items || [], [data]);
+
+ // Picking a billing model stages a single mapping for confirmation; the
+ // mapping only commits once the user confirms in the dialog. Kept in a store
+ // (not local state) so the row's memoized select trigger can mirror the pick —
+ // see usePendingMappingStore.
+ const pendingMapping = usePendingMappingStore((state) => state.pending);
+ const setPending = usePendingMappingStore((state) => state.setPending);
+ const clearPending = usePendingMappingStore((state) => state.clearPending);
+ const { mapModel, isSaving } = useUnpricedModelMapping();
+
+ // Reset any staged mapping when leaving the tab so a stale pick doesn't reopen
+ // the dialog on remount (the store outlives this component).
+ useEffect(() => (): void => clearPending(), [clearPending]);
+
+ // Reuses the "Model costs" add/edit drawer to define brand-new pricing for a
+ // model that has no matching billing model to map onto. Saving resolves the
+ // model, so it drops off this tab (the drawer invalidates the unmapped list).
+ const drawer = useModelCostDrawer();
+
+ const onRequestMap = useCallback(
+ (model: UnpricedModel, rule: PricingRule): void => {
+ setPending({ model, rule });
+ },
+ [setPending],
+ );
+
+ const onConfirmMap = useCallback(async (): Promise<void> => {
+ if (!pendingMapping) {
+ return;
+ }
+ const didSave = await mapModel(pendingMapping);
+ if (didSave) {
+ clearPending();
+ }
+ }, [mapModel, pendingMapping, clearPending]);
+
+ // openForAdd is stable (useCallback with no deps); drawer itself is a fresh
+ // object each render, so depend on the method, not the object.
+ const { openForAdd } = drawer;
+ const onCreateNew = useCallback(
+ (modelName: string): void => openForAdd(modelName),
+ [openForAdd],
+ );
+ const columnsConfig = useMemo<UnpricedColumnsConfig>(
+ () => ({
+ canManage: canManagePricing,
+ onRequestMap,
+ onCreateNew,
+ }),
+ [canManagePricing, onRequestMap, onCreateNew],
+ );
+
+ return (
+ <div className={styles.unpricedModelsTab}>
+ <div className={styles.banner}>
+ <TriangleAlert size="sm" className={styles.bannerIcon} />
+ <Typography.Text as="span" size="small" color="warning">
+ Models detected in traces without pricing. Map each to a billing model or
+ create pricing so estimated cost can be computed.
+ </Typography.Text>
+ </div>
+
+ {isError && (
+ <div className={styles.error}>
+ <Typography.Text as="p" size="small" color="danger" role="alert">
+ Failed to load unpriced models. Please try again.
+ </Typography.Text>
+ </div>
+ )}
+
+ <UnpricedModelsTable
+ models={models}
+ isLoading={isLoading}
+ columnsConfig={columnsConfig}
+ />
+
+ {pendingMapping && (
+ <MapConfirmDialog
+ open
+ model={pendingMapping.model}
+ rule={pendingMapping.rule}
+ isSaving={isSaving}
+ onConfirm={onConfirmMap}
+ onCancel={clearPending}
+ />
+ )}
+
+ {drawer.isOpen && (
+ <ModelCostDrawer
+ isOpen={drawer.isOpen}
+ mode={drawer.mode}
+ initialDraft={drawer.initialDraft}
+ onClose={drawer.close}
+ onSave={drawer.save}
+ isSaving={drawer.isSaving}
+ saveError={drawer.saveError}
+ canManage={canManagePricing}
+ />
+ )}
+ </div>
+ );
+}
+
+export default UnpricedModelsTab;
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/__tests__/UnpricedModelsTab.test.tsx b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/__tests__/UnpricedModelsTab.test.tsx
new file mode 100644
index 0000000000..c70974e9bf
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/__tests__/UnpricedModelsTab.test.tsx
@@ -0,0 +1,181 @@
+import type { LlmpricingruletypesUpdatableLLMPricingRulesDTO } from 'api/generated/services/sigNoz.schemas';
+import {
+ LLM_PRICING_ENDPOINT,
+ LLM_UNMAPPED_ENDPOINT,
+ makeListResponse,
+ makeUnmappedResponse,
+ mockRules,
+} from 'container/LLMObservability/Settings/ModelPricing/__tests__/fixtures';
+import { rest, server } from 'mocks-server/server';
+import { render, screen, userEvent, waitFor, within } from 'tests/test-utils';
+
+import UnpricedModelsTab from '../UnpricedModelsTab';
+
+const toastSuccess = jest.fn();
+const toastError = jest.fn();
+jest.mock('@signozhq/ui/sonner', () => ({
+ ...jest.requireActual('@signozhq/ui/sonner'),
+ toast: {
+ success: (...args: unknown[]): void => toastSuccess(...args),
+ error: (...args: unknown[]): void => toastError(...args),
+ },
+}));
+
+const MODEL = 'gpt-4o-mini-2024-07-18';
+
+function setup(): void {
+ server.use(
+ rest.get(LLM_UNMAPPED_ENDPOINT, (_req, res, ctx) =>
+ res(ctx.status(200), ctx.json(makeUnmappedResponse())),
+ ),
+ rest.get(LLM_PRICING_ENDPOINT, (_req, res, ctx) =>
+ res(ctx.status(200), ctx.json(makeListResponse(mockRules))),
+ ),
+ );
+}
+
+// Picks a billing model in a row's dropdown: open the combobox, then click the
+// option. The dropdown fetches its options from the rules list (mocked above).
+async function selectRule(
+ user: ReturnType<typeof userEvent.setup>,
+ modelName: string,
+ ruleId: string,
+): Promise<void> {
+ await user.click(screen.getByTestId(`map-to-select-${modelName}`));
+ await user.click(await screen.findByTestId(`map-to-option-${ruleId}`));
+}
+
+describe('UnpricedModelsTab (integration)', () => {
+ beforeEach(() => {
+ window.history.pushState(null, '', '/');
+ setup();
+ });
+
+ afterEach(() => {
+ server.resetHandlers();
+ toastSuccess.mockClear();
+ toastError.mockClear();
+ });
+
+ it('opens the confirm dialog with the target rule pricing when a model is picked', async () => {
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<UnpricedModelsTab />);
+
+ await screen.findByTestId(`unpriced-model-name-${MODEL}`);
+
+ // Picking a rule stages the mapping in the confirm dialog.
+ await selectRule(user, MODEL, 'rule-openai');
+
+ const confirmItem = await screen.findByTestId(
+ `unpriced-map-confirm-item-${MODEL}`,
+ );
+ expect(confirmItem).toBeInTheDocument();
+ // Shows the target billing model + its pricing so the user can eyeball it.
+ expect(screen.getByText('openai:gpt-4o')).toBeInTheDocument();
+ expect(screen.getByText('$3.00')).toBeInTheDocument();
+ expect(screen.getByText('$9.00')).toBeInTheDocument();
+ // While the dialog is open, the row's trigger mirrors the staged pick
+ // instead of the placeholder.
+ const trigger = screen.getByTestId(`map-to-select-${MODEL}`);
+ expect(
+ within(trigger).getByText('openai:gpt-4o ($3.00/$9.00)'),
+ ).toBeInTheDocument();
+ });
+
+ it('reverts the row trigger to the placeholder when the mapping is cancelled', async () => {
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<UnpricedModelsTab />);
+
+ await screen.findByTestId(`unpriced-model-name-${MODEL}`);
+ await selectRule(user, MODEL, 'rule-openai');
+
+ const trigger = screen.getByTestId(`map-to-select-${MODEL}`);
+ expect(
+ within(trigger).getByText('openai:gpt-4o ($3.00/$9.00)'),
+ ).toBeInTheDocument();
+
+ await user.click(await screen.findByTestId('unpriced-map-cancel-btn'));
+
+ await waitFor(() =>
+ expect(
+ within(trigger).queryByText('openai:gpt-4o ($3.00/$9.00)'),
+ ).not.toBeInTheDocument(),
+ );
+ expect(
+ within(trigger).getByText('Select / Create a pricing model'),
+ ).toBeInTheDocument();
+ });
+
+ it('commits the mapping in one request when confirmed', async () => {
+ const sent: LlmpricingruletypesUpdatableLLMPricingRulesDTO[] = [];
+ server.use(
+ rest.put(LLM_PRICING_ENDPOINT, async (req, res, ctx) => {
+ sent.push(await req.json());
+ return res(ctx.status(200), ctx.json({ status: 'success' }));
+ }),
+ );
+
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<UnpricedModelsTab />);
+
+ await screen.findByTestId(`unpriced-model-name-${MODEL}`);
+ await selectRule(user, MODEL, 'rule-openai');
+
+ await user.click(await screen.findByTestId('unpriced-map-confirm-btn'));
+
+ await waitFor(() => expect(sent).toHaveLength(1));
+ expect(sent[0].rules).toHaveLength(1);
+ expect(sent[0].rules?.[0].modelPattern).toContain(MODEL);
+ await waitFor(() =>
+ expect(toastSuccess).toHaveBeenCalledWith('Mapped model'),
+ );
+ // Dialog closes on success.
+ await waitFor(() =>
+ expect(
+ screen.queryByTestId(`unpriced-map-confirm-item-${MODEL}`),
+ ).not.toBeInTheDocument(),
+ );
+ });
+
+ it('cancels the mapping without committing', async () => {
+ const sent: LlmpricingruletypesUpdatableLLMPricingRulesDTO[] = [];
+ server.use(
+ rest.put(LLM_PRICING_ENDPOINT, async (req, res, ctx) => {
+ sent.push(await req.json());
+ return res(ctx.status(200), ctx.json({ status: 'success' }));
+ }),
+ );
+
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<UnpricedModelsTab />);
+
+ await screen.findByTestId(`unpriced-model-name-${MODEL}`);
+ await selectRule(user, MODEL, 'rule-openai');
+
+ await user.click(await screen.findByTestId('unpriced-map-cancel-btn'));
+
+ await waitFor(() =>
+ expect(
+ screen.queryByTestId(`unpriced-map-confirm-item-${MODEL}`),
+ ).not.toBeInTheDocument(),
+ );
+ expect(sent).toHaveLength(0);
+ });
+
+ it('opens the add-cost drawer prefilled when creating pricing for a model', async () => {
+ const user = userEvent.setup({ pointerEventsCheck: 0 });
+ render(<UnpricedModelsTab />);
+
+ await screen.findByTestId(`unpriced-model-name-${MODEL}`);
+
+ // Open the row's dropdown and take the "Create pricing for …" escape hatch
+ // instead of mapping onto an existing billing model.
+ await user.click(screen.getByTestId(`map-to-select-${MODEL}`));
+ await user.click(await screen.findByTestId(`map-to-create-${MODEL}`));
+
+ // The shared add-cost drawer opens with the model name prefilled.
+ const drawerTitle = await screen.findByText('Add model cost');
+ expect(drawerTitle).toBeInTheDocument();
+ expect(screen.getByTestId('drawer-model-id-input')).toHaveValue(MODEL);
+ });
+});
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/MapConfirmDialog.module.scss b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/MapConfirmDialog.module.scss
new file mode 100644
index 0000000000..7ccd2a645b
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/MapConfirmDialog.module.scss
@@ -0,0 +1,40 @@
+.body {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-6);
+}
+
+.mapping {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-4);
+ flex-wrap: wrap;
+}
+
+.arrow {
+ flex-shrink: 0;
+ opacity: 0.6;
+}
+
+.pricing {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-3);
+ padding: var(--spacing-6);
+ border-radius: var(--radius-2);
+ border: 1px solid var(--l2-border);
+ background: var(--l3-background);
+}
+
+.pricingRow {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ gap: var(--spacing-6);
+}
+
+.footer {
+ display: flex;
+ justify-content: flex-end;
+ gap: var(--spacing-4);
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/MapConfirmDialog.tsx b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/MapConfirmDialog.tsx
new file mode 100644
index 0000000000..a8dcc36486
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/MapConfirmDialog.tsx
@@ -0,0 +1,124 @@
+import { Button } from '@signozhq/ui/button';
+import { DialogWrapper } from '@signozhq/ui/dialog';
+import { Typography } from '@signozhq/ui/typography';
+import { ArrowRight, Check, Link2, X } from '@signozhq/icons';
+import { startCase } from 'lodash-es';
+
+import styles from './MapConfirmDialog.module.scss';
+import type {
+ PricingRule,
+ UnpricedModel,
+} from 'container/LLMObservability/Settings/ModelPricing/types';
+import {
+ formatPricePerMillion,
+ getCanonicalId,
+ getExtraBuckets,
+} from 'container/LLMObservability/Settings/ModelPricing/utils';
+
+interface MapConfirmDialogProps {
+ open: boolean;
+ model: UnpricedModel;
+ rule: PricingRule;
+ isSaving: boolean;
+ onConfirm: () => void;
+ onCancel: () => void;
+}
+
+// Per-row confirm step before mapping an unpriced model onto an existing billing
+// model. Mapping appends the span's model name as a match pattern on the chosen
+// rule, so the model inherits that rule's pricing — shown here so the user can
+// eyeball the rates before committing. Dismissible (outside click / close), since
+// mapping is reversible (re-map or edit the rule's patterns afterwards).
+function MapConfirmDialog({
+ open,
+ model,
+ rule,
+ isSaving,
+ onConfirm,
+ onCancel,
+}: MapConfirmDialogProps): JSX.Element {
+ const extraBuckets = getExtraBuckets(rule);
+
+ const pricingRows = [
+ { key: 'input', label: 'Input / 1M', value: rule.pricing?.input },
+ { key: 'output', label: 'Output / 1M', value: rule.pricing?.output },
+ ...extraBuckets.map((bucket) => ({
+ key: bucket.key,
+ label: startCase(bucket.key),
+ value: bucket.pricePerMillion,
+ })),
+ ];
+
+ const footer = (
+ <div className={styles.footer}>
+ <Button
+ variant="outlined"
+ color="secondary"
+ onClick={onCancel}
+ disabled={isSaving}
+ prefix={<X size={12} />}
+ testId="unpriced-map-cancel-btn"
+ >
+ Cancel
+ </Button>
+ <Button
+ variant="solid"
+ color="primary"
+ loading={isSaving}
+ onClick={onConfirm}
+ prefix={<Check size={12} />}
+ testId="unpriced-map-confirm-btn"
+ >
+ Map model
+ </Button>
+ </div>
+ );
+
+ return (
+ <DialogWrapper
+ open={open}
+ onOpenChange={(isOpen): void => {
+ if (!isOpen) {
+ onCancel();
+ }
+ }}
+ width="base"
+ title="Map to billing model"
+ titleIcon={<Link2 size={16} />}
+ footer={footer}
+ testId="unpriced-map-confirm-dialog"
+ >
+ <div className={styles.body}>
+ <Typography.Text as="p" size="small" color="muted">
+ Spans from this model will be priced using the selected billing model.
+ </Typography.Text>
+
+ <div className={styles.mapping}>
+ <Typography.Text
+ weight="semibold"
+ testId={`unpriced-map-confirm-item-${model.modelName}`}
+ >
+ {model.modelName}
+ </Typography.Text>
+ <ArrowRight size={14} className={styles.arrow} />
+ <Typography.Text weight="semibold">{getCanonicalId(rule)}</Typography.Text>
+ </div>
+
+ <div className={styles.pricing}>
+ {pricingRows.map((row) => (
+ <div className={styles.pricingRow} key={row.key}>
+ <Typography.Text as="span" size="small" color="muted">
+ {row.label}
+ </Typography.Text>
+ <Typography.Text as="span" size="small" weight="semibold">
+ {formatPricePerMillion(row.value)}
+ </Typography.Text>
+ </div>
+ ))}
+ </div>
+ </div>
+ </DialogWrapper>
+ );
+}
+
+export default MapConfirmDialog;
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/index.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/index.ts
new file mode 100644
index 0000000000..83306e5f8a
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapConfirmDialog/index.ts
@@ -0,0 +1 @@
+export { default } from './MapConfirmDialog';
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/MapToBillingModelSelect.module.scss b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/MapToBillingModelSelect.module.scss
new file mode 100644
index 0000000000..160f478091
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/MapToBillingModelSelect.module.scss
@@ -0,0 +1,27 @@
+.mapToCell {
+ display: flex;
+ align-items: center;
+ gap: var(--spacing-1);
+ min-width: 0;
+}
+
+.mapToSelect {
+ width: 100%;
+ max-width: 280px;
+}
+
+.mapToDropdown {
+ width: 280px;
+}
+
+.skeletonList {
+ display: flex;
+ flex-direction: column;
+ gap: var(--spacing-3);
+ padding: var(--spacing-3) var(--spacing-4);
+}
+
+.skeletonRow {
+ display: block;
+ width: 100%;
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/MapToBillingModelSelect.tsx b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/MapToBillingModelSelect.tsx
new file mode 100644
index 0000000000..65586e8e85
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/MapToBillingModelSelect.tsx
@@ -0,0 +1,138 @@
+import { useState } from 'react';
+import {
+ Combobox,
+ ComboboxCommand,
+ ComboboxContent,
+ ComboboxCreateItem,
+ ComboboxEmpty,
+ ComboboxInput,
+ ComboboxItem,
+ ComboboxList,
+ ComboboxSeparator,
+ ComboboxTrigger,
+} from '@signozhq/ui/combobox';
+import { Plus } from '@signozhq/icons';
+import { Skeleton } from 'antd';
+
+import styles from './MapToBillingModelSelect.module.scss';
+import { RULE_OPTIONS_LIMIT } from 'container/LLMObservability/Settings/ModelPricing/constants';
+import type { PricingRule } from 'container/LLMObservability/Settings/ModelPricing/types';
+import { getRuleOptionLabel } from 'container/LLMObservability/Settings/ModelPricing/utils';
+import { usePendingMappingLabel } from 'container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/usePendingMappingStore';
+import { useMapToBillingModelSearch } from './useMapToBillingModelSearch';
+
+// One placeholder row per fetched option, so the skeleton height matches the
+// loaded list. Stable keys derived from the fetch limit.
+const SKELETON_ROW_KEYS = Array.from(
+ { length: RULE_OPTIONS_LIMIT },
+ (_, index) => `skeleton-${index}`,
+);
+
+interface MapToBillingModelSelectProps {
+ modelName: string;
+ disabled: boolean;
+ onSelect: (rule: PricingRule) => void;
+ onCreateNew: () => void;
+}
+
+// Searchable, server-paged dropdown for picking the billing model an unpriced
+// model maps onto. Only RULE_OPTIONS_LIMIT rules are fetched at a time; typing
+// narrows the set via the rules API rather than client-side filtering, so cmdk's
+// own filter is disabled (shouldFilter={false}). The dropdown is a pure picker —
+// choosing a rule hands it up to the confirm dialog rather than persisting a
+// selection here. The trigger only mirrors the staged pick (read from the
+// pending-mapping store) while that dialog is open, reverting on confirm/cancel.
+function MapToBillingModelSelect({
+ modelName,
+ disabled,
+ onSelect,
+ onCreateNew,
+}: MapToBillingModelSelectProps): JSX.Element {
+ const [open, setOpen] = useState(false);
+ const { searchText, setSearchText, rules, rulesById, isFetching } =
+ useMapToBillingModelSearch(open);
+ const selectedLabel = usePendingMappingLabel(modelName);
+
+ const handleSelect = (ruleId: string): void => {
+ const rule = rulesById.get(ruleId);
+ if (rule) {
+ onSelect(rule);
+ }
+ setOpen(false);
+ };
+
+ const handleCreateNew = (): void => {
+ setOpen(false);
+ onCreateNew();
+ };
+
+ return (
+ <div className={styles.mapToCell}>
+ <Combobox open={open} onOpenChange={setOpen}>
+ <ComboboxTrigger
+ className={styles.mapToSelect}
+ disabled={disabled}
+ placeholder="Select / Create a pricing model"
+ value={selectedLabel}
+ testId={`map-to-select-${modelName}`}
+ />
+ <ComboboxContent className={styles.mapToDropdown}>
+ <ComboboxCommand shouldFilter={false}>
+ <ComboboxInput
+ value={searchText}
+ onValueChange={setSearchText}
+ placeholder="Search billing models"
+ testId={`map-to-search-${modelName}`}
+ />
+ <ComboboxList>
+ {rules.map((rule) => (
+ <ComboboxItem
+ key={rule.id}
+ value={rule.id}
+ onSelect={(): void => handleSelect(rule.id)}
+ data-testid={`map-to-option-${rule.id}`}
+ >
+ {getRuleOptionLabel(rule)}
+ </ComboboxItem>
+ ))}
+ {isFetching && (
+ <div
+ className={styles.skeletonList}
+ data-testid={`map-to-loading-${modelName}`}
+ >
+ {SKELETON_ROW_KEYS.map((key) => (
+ <Skeleton.Input
+ key={key}
+ active
+ block
+ size="small"
+ className={styles.skeletonRow}
+ />
+ ))}
+ </div>
+ )}
+ {!isFetching && rules.length === 0 && (
+ <ComboboxEmpty>No billing models found</ComboboxEmpty>
+ )}
+ </ComboboxList>
+ {/* Kept outside ComboboxList so it stays pinned as a footer while the
+ options scroll. Escape hatch when no existing billing model fits:
+ define this model's own pricing rather than mapping onto another. */}
+ <ComboboxSeparator alwaysRender />
+ <ComboboxCreateItem
+ inputValue={modelName}
+ value={`create-pricing-${modelName}`}
+ prefix={<Plus size={14} />}
+ onSelect={handleCreateNew}
+ testId={`map-to-create-${modelName}`}
+ >
+ Create pricing for &quot;{modelName}&quot;
+ </ComboboxCreateItem>
+ </ComboboxCommand>
+ </ComboboxContent>
+ </Combobox>
+ </div>
+ );
+}
+
+export default MapToBillingModelSelect;
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/index.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/index.ts
new file mode 100644
index 0000000000..70ca3ffc2f
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/index.ts
@@ -0,0 +1 @@
+export { default } from './MapToBillingModelSelect';
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/useMapToBillingModelSearch.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/useMapToBillingModelSearch.ts
new file mode 100644
index 0000000000..04424f3e8f
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect/useMapToBillingModelSearch.ts
@@ -0,0 +1,44 @@
+import { useMemo, useState } from 'react';
+import { useListLLMPricingRules } from 'api/generated/services/llmpricingrules';
+import useDebounce from 'hooks/useDebounce';
+
+import {
+ RULE_OPTIONS_LIMIT,
+ SEARCH_DEBOUNCE_MS,
+} from 'container/LLMObservability/Settings/ModelPricing/constants';
+import type { PricingRule } from 'container/LLMObservability/Settings/ModelPricing/types';
+
+interface UseMapToBillingModelSearch {
+ searchText: string;
+ setSearchText: (value: string) => void;
+ rules: PricingRule[];
+ // Fetched rules keyed by id, so a pick can resolve to its full rule object.
+ rulesById: Map<string, PricingRule>;
+ isFetching: boolean;
+}
+
+// Server-side search for the per-row "Map to billing model" dropdown. Only
+// RULE_OPTIONS_LIMIT rules are fetched at a time; typing narrows the set via the
+// rules API's `q` param instead of filtering client-side. The fetch is gated on
+// `enabled` (the dropdown's open state) so closed rows don't fetch, and
+// react-query dedupes identical query keys so rows sharing a term hit the network
+// once.
+export function useMapToBillingModelSearch(
+ enabled: boolean,
+): UseMapToBillingModelSearch {
+ const [searchText, setSearchText] = useState('');
+ const debouncedSearch = useDebounce(searchText, SEARCH_DEBOUNCE_MS);
+
+ const { data, isFetching } = useListLLMPricingRules(
+ { offset: 0, limit: RULE_OPTIONS_LIMIT, q: debouncedSearch || undefined },
+ { query: { enabled } },
+ );
+
+ const rules = useMemo<PricingRule[]>(() => data?.data?.items || [], [data]);
+ const rulesById = useMemo(
+ () => new Map(rules.map((rule) => [rule.id, rule])),
+ [rules],
+ );
+
+ return { searchText, setSearchText, rules, rulesById, isFetching };
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/index.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/index.ts
new file mode 100644
index 0000000000..ecadfe7955
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/index.ts
@@ -0,0 +1,2 @@
+export { getUnpricedModelsColumns } from './table.config';
+export type { UnpricedColumnsConfig } from './table.config';
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/table.config.tsx b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/table.config.tsx
new file mode 100644
index 0000000000..e8143d9b08
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/table.config.tsx
@@ -0,0 +1,88 @@
+import { Badge } from '@signozhq/ui/badge';
+import { Typography } from '@signozhq/ui/typography';
+import type { TableColumnDef } from 'components/TanStackTableView';
+
+import MapToBillingModelSelect from 'container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/MapToBillingModelSelect';
+import type {
+ PricingRule,
+ UnpricedModel,
+} from 'container/LLMObservability/Settings/ModelPricing/types';
+import { formatSpanCount } from 'container/LLMObservability/Settings/ModelPricing/utils';
+import styles from './tableConfig.module.scss';
+
+export interface UnpricedColumnsConfig {
+ canManage: boolean;
+ // Picking a billing model requests a mapping — the tab opens a confirm dialog
+ // and commits that single mapping there (no batch/selection state here).
+ onRequestMap: (model: UnpricedModel, rule: PricingRule) => void;
+ // Opens the add-cost drawer prefilled with the row's model name.
+ onCreateNew: (modelName: string) => void;
+}
+
+// Column definitions for the unpriced-models TanStackTable. Sorting is off — the
+// unmapped-models endpoint returns the full set in one shot with no ordering knob.
+// Each row's action is self-contained: pick a billing model to map onto (confirmed
+// in a dialog) or create pricing for the model, so there's no bulk-save column.
+export function getUnpricedModelsColumns({
+ canManage,
+ onRequestMap,
+ onCreateNew,
+}: UnpricedColumnsConfig): TableColumnDef<UnpricedModel>[] {
+ return [
+ {
+ id: 'model',
+ header: 'Model (from spans)',
+ accessorFn: (row): string => row.modelName,
+ width: { min: 240, default: '100%' },
+ enableMove: false,
+ enableRemove: false,
+ cell: ({ row }): JSX.Element => (
+ <Typography.Text
+ weight="semibold"
+ truncate={1}
+ testId={`unpriced-model-name-${row.modelName}`}
+ >
+ {row.modelName}
+ </Typography.Text>
+ ),
+ },
+ {
+ id: 'provider',
+ header: 'Provider',
+ width: { min: 140 },
+ enableMove: false,
+ cell: ({ row }): string => row.provider || 'Unknown',
+ },
+ {
+ id: 'spans',
+ header: 'Spans',
+ width: { min: 100 },
+ enableMove: false,
+ cell: ({ row }): JSX.Element => (
+ <Badge
+ color="cherry"
+ variant="outline"
+ className={styles.spansBadge}
+ data-testid={`unpriced-spans-${row.modelName}`}
+ >
+ {formatSpanCount(row.spanCount)}
+ </Badge>
+ ),
+ },
+ {
+ id: 'mapTo',
+ header: 'Map to billing model',
+ width: { min: 280, default: '100%' },
+ enableMove: false,
+ enableRemove: false,
+ cell: ({ row }): JSX.Element => (
+ <MapToBillingModelSelect
+ modelName={row.modelName}
+ disabled={!canManage}
+ onSelect={(rule): void => onRequestMap(row, rule)}
+ onCreateNew={(): void => onCreateNew(row.modelName)}
+ />
+ ),
+ },
+ ];
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/tableConfig.module.scss b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/tableConfig.module.scss
new file mode 100644
index 0000000000..aad108f7ee
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/TableConfig/tableConfig.module.scss
@@ -0,0 +1,4 @@
+.spansBadge {
+ margin: 0;
+ font-family: var(--code-font-family, monospace);
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/UnpricedModelsTable.module.scss b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/UnpricedModelsTable.module.scss
new file mode 100644
index 0000000000..6f59d28a3c
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/UnpricedModelsTable.module.scss
@@ -0,0 +1,22 @@
+// Capped scroll viewport — mirrors ModelCostsTable so the unpriced tab doesn't
+// shift on load, but uses max-height so a short list stays compact instead of
+// reserving the full viewport. The extra offset over the model-costs table
+// accounts for the banner toolbar above.
+.unpricedModelsTable {
+ --tanstack-table-row-height: 48px;
+ max-height: calc(100vh - 220px);
+ overflow-y: auto;
+
+ :global(table) tbody tr {
+ cursor: default;
+ }
+}
+
+.unpricedModelsEmpty {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ min-height: 400px;
+ color: var(--l3-foreground);
+ font-size: var(--periscope-font-size-base);
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/UnpricedModelsTable.tsx b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/UnpricedModelsTable.tsx
new file mode 100644
index 0000000000..f98347358d
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/UnpricedModelsTable.tsx
@@ -0,0 +1,56 @@
+import { useMemo } from 'react';
+import TanStackTable from 'components/TanStackTableView';
+
+import { SKELETON_ROW_COUNT } from 'container/LLMObservability/Settings/ModelPricing/constants';
+import type { UnpricedModel } from 'container/LLMObservability/Settings/ModelPricing/types';
+import styles from './UnpricedModelsTable.module.scss';
+import {
+ getUnpricedModelsColumns,
+ type UnpricedColumnsConfig,
+} from './TableConfig';
+
+interface UnpricedModelsTableProps {
+ models: UnpricedModel[];
+ isLoading: boolean;
+ columnsConfig: UnpricedColumnsConfig;
+}
+
+// The unmapped-models endpoint returns the full set in one response, so there's
+// no pagination here — just a content-height list. Virtual scroll is disabled
+// because the set is small and bounded.
+function UnpricedModelsTable({
+ models,
+ isLoading,
+ columnsConfig,
+}: UnpricedModelsTableProps): JSX.Element {
+ const columns = useMemo(
+ () => getUnpricedModelsColumns(columnsConfig),
+ [columnsConfig],
+ );
+
+ if (!isLoading && models.length === 0) {
+ return (
+ <div
+ className={styles.unpricedModelsEmpty}
+ data-testid="unpriced-models-empty"
+ >
+ All models in your traces are priced.
+ </div>
+ );
+ }
+
+ return (
+ <TanStackTable<UnpricedModel>
+ className={styles.unpricedModelsTable}
+ data={models}
+ columns={columns}
+ isLoading={isLoading}
+ skeletonRowCount={SKELETON_ROW_COUNT}
+ getRowKey={(row): string => row.modelName}
+ disableVirtualScroll
+ testId="unpriced-models-table"
+ />
+ );
+}
+
+export default UnpricedModelsTable;
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/index.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/index.ts
new file mode 100644
index 0000000000..c73fbd93de
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/components/UnpricedModelsTable/index.ts
@@ -0,0 +1 @@
+export { default } from './UnpricedModelsTable';
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/hooks/useUnpricedModelMapping.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/hooks/useUnpricedModelMapping.ts
new file mode 100644
index 0000000000..be955567d0
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/hooks/useUnpricedModelMapping.ts
@@ -0,0 +1,70 @@
+import { useCallback, useState } from 'react';
+import { toast } from '@signozhq/ui/sonner';
+import { useQueryClient } from 'react-query';
+import {
+ getListLLMPricingRulesQueryKey,
+ getListUnmappedLLMModelsQueryKey,
+ useCreateOrUpdateLLMPricingRules,
+} from 'api/generated/services/llmpricingrules';
+
+import type {
+ PricingRule,
+ UnpricedModel,
+} from 'container/LLMObservability/Settings/ModelPricing/types';
+import { buildPatternMappingPayload } from 'container/LLMObservability/Settings/ModelPricing/utils';
+
+// A single row's choice: map this unpriced model onto this billing rule.
+export interface UnpricedModelMapping {
+ model: UnpricedModel;
+ rule: PricingRule;
+}
+
+interface UseUnpricedModelMappingResult {
+ // Commits a single mapping in one request. Resolves true on success so the
+ // caller can close the confirm dialog and clear its staged pick.
+ mapModel: (mapping: UnpricedModelMapping) => Promise<boolean>;
+ // True while the save is in flight, so the confirm button can spin.
+ isSaving: boolean;
+}
+
+// Maps an unpriced model onto an existing pricing rule. There's no dedicated
+// "edit" endpoint — mapping reuses CreateOrUpdate (PUT), appending the model name
+// as a match pattern on the chosen rule so the model inherits its pricing. Both
+// the unmapped list and the rules list are invalidated on success so the mapped
+// model drops out of this tab immediately.
+export function useUnpricedModelMapping(): UseUnpricedModelMappingResult {
+ const queryClient = useQueryClient();
+ const [isSaving, setIsSaving] = useState(false);
+
+ const { mutateAsync: createOrUpdate } = useCreateOrUpdateLLMPricingRules();
+
+ const mapModel = useCallback(
+ async ({ model, rule }: UnpricedModelMapping): Promise<boolean> => {
+ const payload = buildPatternMappingPayload(rule, model.modelName);
+
+ setIsSaving(true);
+ try {
+ await createOrUpdate({ data: { rules: [payload] } });
+ await Promise.all([
+ queryClient.invalidateQueries({
+ queryKey: getListUnmappedLLMModelsQueryKey(),
+ }),
+ queryClient.invalidateQueries({
+ queryKey: getListLLMPricingRulesQueryKey(),
+ }),
+ ]);
+ toast.success('Mapped model');
+ return true;
+ } catch (error) {
+ const message = error instanceof Error ? error.message : 'Mapping failed';
+ toast.error(message);
+ return false;
+ } finally {
+ setIsSaving(false);
+ }
+ },
+ [createOrUpdate, queryClient],
+ );
+
+ return { mapModel, isSaving };
+}
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/index.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/index.ts
new file mode 100644
index 0000000000..8da4f21bbc
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/index.ts
@@ -0,0 +1 @@
+export { default } from './UnpricedModelsTab';
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/usePendingMappingStore.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/usePendingMappingStore.ts
new file mode 100644
index 0000000000..e314c6dfaf
--- /dev/null
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/UnpricedModelsTab/usePendingMappingStore.ts
@@ -0,0 +1,39 @@
+import { create } from 'zustand';
+
+import type { PricingRule, UnpricedModel } from '../types';
+import { getRuleOptionLabel } from '../utils';
+
+// A model + the billing rule it's about to be mapped onto, held while the confirm
+// dialog is open.
+export interface PendingMapping {
+ model: UnpricedModel;
+ rule: PricingRule;
+}
+
+interface PendingMappingState {
+ pending: PendingMapping | null;
+ setPending: (mapping: PendingMapping) => void;
+ clearPending: () => void;
+}
+
+// The staged mapping lives in a store (not component state/props) because the
+// row's select trigger, which mirrors the staged pick, sits inside a memoized
+// TanStackTable cell whose value is cached per row — a prop/context change would
+// not re-render it, but a store subscription does. Picking a billing model stages
+// a single mapping for confirmation; it only commits once confirmed in the dialog.
+export const usePendingMappingStore = create<PendingMappingState>((set) => ({
+ pending: null,
+ setPending: (mapping): void => set({ pending: mapping }),
+ clearPending: (): void => set({ pending: null }),
+}));
+
+// Label to show on the given row's select trigger while its mapping is staged, or
+// undefined when nothing is staged for that row (falls back to the placeholder).
+export const usePendingMappingLabel = (modelName: string): string | undefined =>
+ usePendingMappingStore((state) => {
+ const { pending } = state;
+ if (!pending || pending.model.modelName !== modelName) {
+ return undefined;
+ }
+ return getRuleOptionLabel(pending.rule);
+ });
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/__tests__/fixtures.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/__tests__/fixtures.ts
index 1f06f2573d..d544f8103d 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/__tests__/fixtures.ts
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/__tests__/fixtures.ts
@@ -2,14 +2,19 @@ import {
LlmpricingruletypesLLMPricingRuleCacheModeDTO as CacheModeDTO,
LlmpricingruletypesLLMPricingRuleUnitDTO as UnitDTO,
type ListLLMPricingRules200,
+ type ListUnmappedLLMModels200,
} from 'api/generated/services/sigNoz.schemas';
-import type { PricingRule } from '../types';
+import type { PricingRule, UnpricedModel } from '../types';
// Endpoint glob used by MSW handlers. The generated client hits a relative
// `/api/v1/llm_pricing_rules`, so the `*` prefix matches regardless of base URL.
export const LLM_PRICING_ENDPOINT = '*/api/v1/llm_pricing_rules';
export const LLM_PRICING_RULE_ENDPOINT = '*/api/v1/llm_pricing_rules/:id';
+// Distinct path (extra segment), so it needs its own handler — the list glob
+// above does not match it.
+export const LLM_UNMAPPED_ENDPOINT =
+ '*/api/v1/llm_pricing_rules/unmapped_models';
// Builds a valid pricing rule, with overrides merged shallowly. Pricing is
// replaced wholesale when provided so callers can shape cache buckets freely.
@@ -60,6 +65,26 @@ export const mockRules: PricingRule[] = [
}),
];
+// Unpriced models seen in traces with no matching pricing rule.
+export const mockUnpricedModels: UnpricedModel[] = [
+ { modelName: 'gpt-4o-mini-2024-07-18', provider: 'openai', spanCount: 18400 },
+ {
+ modelName: 'claude-3-7-sonnet-20250219',
+ provider: 'anthropic',
+ spanCount: 9200,
+ },
+];
+
+// Wraps unpriced models in the envelope the unmapped-models query reads.
+export function makeUnmappedResponse(
+ items: UnpricedModel[] = mockUnpricedModels,
+): ListUnmappedLLMModels200 {
+ return {
+ status: 'success',
+ data: { items },
+ };
+}
+
// Wraps items in the list response envelope the list query reads
// (`data.data.items` / `data.data.total`).
export function makeListResponse(
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/constants.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/constants.ts
index 02144e2b1e..8ab48ee533 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/constants.ts
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/constants.ts
@@ -34,6 +34,13 @@ export const SOURCE_FILTER_TO_IS_OVERRIDE: Record<
// loaded page renders — otherwise the table height jumps on load.
export const SKELETON_ROW_COUNT = PAGE_SIZE;
+export const RULE_OPTIONS_LIMIT = 10;
+
+// URL-backed key for the active tab on the model-pricing page.
+export const TAB_KEY = 'tab';
+export const MODEL_COSTS_TAB = 'model-costs';
+export const UNPRICED_MODELS_TAB = 'unpriced-models';
+
export const PROVIDER_OPTIONS = [
{ value: 'OpenAI', label: 'OpenAI' },
{ value: 'Anthropic', label: 'Anthropic' },
@@ -62,6 +69,7 @@ export const EMPTY_DRAFT: DrawerDraft = {
provider: 'OpenAI',
patterns: [],
isOverride: true,
+ enabled: true,
pricing: {
input: null,
output: null,
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/types.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/types.ts
index dfac6f2eee..711e66a957 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/types.ts
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/types.ts
@@ -1,10 +1,14 @@
import {
LlmpricingruletypesLLMPricingRuleCacheModeDTO as CacheModeDTO,
type LlmpricingruletypesLLMPricingRuleDTO,
+ type LlmpricingruletypesUnmappedModelDTO,
} from 'api/generated/services/sigNoz.schemas';
export type PricingRule = LlmpricingruletypesLLMPricingRuleDTO;
+// A model seen in trace data (gen_ai.request.model) that no pricing rule matches.
+export type UnpricedModel = LlmpricingruletypesUnmappedModelDTO;
+
export interface ExtraBucket {
key: string;
pricePerMillion: number;
@@ -29,6 +33,7 @@ export interface DrawerDraft {
provider: string;
patterns: string[];
isOverride: boolean;
+ enabled: boolean;
pricing: {
input: number | null;
output: number | null;
diff --git a/frontend/src/container/LLMObservability/Settings/ModelPricing/utils.ts b/frontend/src/container/LLMObservability/Settings/ModelPricing/utils.ts
index 16083238f8..1570d8fc58 100644
--- a/frontend/src/container/LLMObservability/Settings/ModelPricing/utils.ts
+++ b/frontend/src/container/LLMObservability/Settings/ModelPricing/utils.ts
@@ -86,6 +86,7 @@ export const draftFromRule = (rule: PricingRule): DrawerDraft => ({
provider: rule.provider,
patterns: rule.modelPattern || [],
isOverride: !!rule.isOverride,
+ enabled: rule.enabled,
pricing: {
input: rule.pricing?.input ?? 0,
output: rule.pricing?.output ?? 0,
@@ -129,7 +130,7 @@ export const buildRulePayload = (
provider: draft.provider.trim(),
modelPattern: draft.patterns,
isOverride: draft.isOverride,
- enabled: true,
+ enabled: draft.enabled,
unit: UnitDTO.per_million_tokens,
pricing: buildPricingPayload(draft),
});
@@ -161,3 +162,38 @@ export const validatePricing = (
}
return true;
};
+
+const spanCountFormatter = new Intl.NumberFormat('en', {
+ notation: 'compact',
+ maximumFractionDigits: 1,
+});
+
+export const formatSpanCount = (count: number): string =>
+ spanCountFormatter.format(count);
+
+// Label for the "Map to billing model" dropdown, e.g. "openai:gpt-4o ($15.00/$60.00)".
+export const getRuleOptionLabel = (rule: PricingRule): string =>
+ `${getCanonicalId(rule)} (${formatPricePerMillion(
+ rule.pricing?.input,
+ )}/${formatPricePerMillion(rule.pricing?.output)})`;
+
+export const buildPatternMappingPayload = (
+ rule: PricingRule,
+ modelName: string,
+): LlmpricingruletypesUpdatableLLMPricingRuleDTO => {
+ const existing = rule.modelPattern ?? [];
+ const modelPattern = existing.includes(modelName)
+ ? existing
+ : [...existing, modelName];
+ return {
+ id: rule.id,
+ sourceId: rule.sourceId,
+ modelName: rule.modelName,
+ provider: rule.provider,
+ modelPattern,
+ isOverride: rule.isOverride,
+ enabled: rule.enabled,
+ unit: rule.unit,
+ pricing: rule.pricing,
+ };
+};