feat(usage): surface Gemini thinkingConfig as reasoning effort

Usage records show a reasoning badge next to the model name for OpenAI and
Claude requests, but Gemini requests never got one. The extraction only read
the OpenAI/Claude shapes (`reasoning_effort`, `reasoning.effort`,
`output_config.effort`), while Gemini states its reasoning depth inside
`generationConfig.thinkingConfig` — so nothing was written to the usage
metadata and the list and detail views had no badge to render.

Read the Gemini shape too, as a fallback after the existing three so the
OpenAI and Claude paths are untouched:

- `thinkingLevel` / `thinking_level` wins when present, trimmed and
  lowercased, with the protobuf enum prefix stripped so `THINKING_LEVEL_HIGH`
  resolves like `high`.
- Otherwise `thinkingBudget` / `thinking_budget` goes through the existing
  shared budget ladder, yielding the same `low|medium|high|xhigh` vocabulary
  the badge already understands.
- Both camelCase and snake_case spellings are read, so a captured client body
  and a converted provider body resolve to the same label.
- `includeThoughts` alone is a visibility flag, not a depth, and produces no
  badge.

Two cases are handled explicitly rather than through the shared ladder:

- `thinkingBudget: 0` disables reasoning outright. The shared ladder maps
  `0..=1664` to `low`, which would report an explicitly disabled request as a
  shallow one, so it reports `none` instead.
- `THINKING_LEVEL_UNSPECIFIED` is the enum's "no explicit level" member, not a
  depth; it is rejected rather than surfaced as an `unspecified` badge.

The frontend needs no change: `UsageModelDisplay` already renders the badge
whenever the fields are present, and keeps the `high -> xhigh` mapping format
when the requested and upstream efforts differ.
This commit is contained in:
Kayphoon
2026-09-18 07:15:59 +00:00
parent fb25dde4c9
commit b296d46e97
5 changed files with 359 additions and 0 deletions
@@ -631,6 +631,53 @@ describe('RequestDetailDrawer settlement pricing', () => {
})
})
it('shows the Gemini thinkingConfig reasoning effort in the model header', async () => {
apiMocks.getRequestDetail.mockResolvedValue({
...buildEmbeddingDetail(),
id: 'usage-gemini-thinking',
request_id: 'usage-gemini-thinking',
model: 'gemini-3.8-flash',
request_type: 'chat',
requested_reasoning_effort: 'xhigh',
reasoning_effort: 'high',
request_body: {
generationConfig: {
thinkingConfig: { includeThoughts: true, thinkingLevel: 'HIGH' },
},
},
provider_request_body: {
generationConfig: { thinkingConfig: { thinkingBudget: 8192 } },
},
})
let isOpen!: Ref<boolean>
const Host = defineComponent({
setup() {
isOpen = ref(false)
return () => h(RequestDetailDrawer, {
isOpen: isOpen.value,
requestId: 'usage-gemini-thinking',
})
},
})
const root = document.createElement('div')
document.body.appendChild(root)
const app = createApp(Host)
app.mount(root)
mountedApps.push({ app, root })
isOpen.value = true
await nextTick()
await vi.waitFor(() => {
expect(document.body.querySelector('[data-request-detail-model-display]')?.textContent)
.toContain('gemini-3.8-flash')
expect(document.body.querySelector('[data-request-detail-model-badge="reasoning"]')?.textContent?.trim())
.toBe('xhigh -> high')
})
})
it('lets a newer final-provider summary clear facts cached from an earlier candidate', async () => {
apiMocks.getRequestDetail.mockResolvedValue({
...buildEmbeddingDetail(),
@@ -439,6 +439,42 @@ describe('UsageRecordsTable', () => {
.toBe('Fast')
})
it('shows the Gemini thinkingLevel reasoning effort next to the model name', () => {
const root = mountUsageRecordsTable([buildRecord({
model: 'gemini-3.8-flash',
requested_reasoning_effort: 'high',
reasoning_effort: 'high',
})])
expect(root.textContent).toContain('gemini-3.8-flash')
const badge = root.querySelector('[data-usage-model-badge="reasoning"]')
expect(badge?.textContent?.trim()).toBe('high')
expect(badge?.getAttribute('title')).toBe('Reasoning: high')
})
it('shows the Gemini thinkingLevel mapping when request and provider disagree', () => {
const root = mountUsageRecordsTable([buildRecord({
model: 'gemini-3.8-flash',
requested_reasoning_effort: 'xhigh',
reasoning_effort: 'high',
})])
expect(root.textContent).toContain('xhigh -> high')
expect(root.querySelector('[data-usage-model-badge="reasoning"]')?.textContent?.trim())
.toBe('xhigh -> high')
})
it('shows a disabled Gemini thinkingBudget as none', () => {
const root = mountUsageRecordsTable([buildRecord({
model: 'gemini-3.8-flash',
requested_reasoning_effort: null,
reasoning_effort: 'none',
})])
expect(root.querySelector('[data-usage-model-badge="reasoning"]')?.textContent?.trim())
.toBe('none')
})
it('shows request reasoning effort while the record is pending', () => {
const root = mountUsageRecordsTable([buildRecord({
status: 'pending',