Skip to content

fix(gateway): log initial requested model ID - #990

Merged
steebchen merged 1 commit into
mainfrom
steebchen/save-requested-model-id
Oct 4, 2025
Merged

steebchen merged 1 commit into
mainfrom
steebchen/save-requested-model-id

Conversation

@steebchen

@steebchen steebchen commented Oct 4, 2025 •

Copy link
Copy Markdown
Member

Summary

Fixes logging to use the original llmgateway model ID instead of the provider-specific rewritten model name.

Changes

  • Added initialRequestedModel variable to preserve the original user-provided model ID
  • Updated all createLogEntry() calls (8 locations) to use initialRequestedModel instead of requestedModel
  • Updated error response to include the initial requested model ID for consistency

Problem

Previously, when a user requested a model like "gpt-4o-mini" or "openai/gpt-4o-mini", the code would rewrite requestedModel to the provider-specific model name (e.g., the actual model name used by the provider API). This rewritten value was then saved to the log table, making it difficult to track what the user originally requested.

Solution

Now the original llmgateway model ID from user input is preserved in initialRequestedModel and used for all logging purposes, while requestedModel can still be used for provider-specific API calls.

Test plan

  • Code formatted with pnpm format
  • Manual testing to verify logs contain correct model IDs
  • E2E tests pass

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Response metadata now consistently reflects the originally requested model, eliminating mismatches after routing or normalization.
  • Chores
    • Enhanced logging to preserve the originally requested model throughout request handling, improving auditability and traceability.
    • Standardized log entries and response details for clearer diagnostics and support.

Store and use the original llmgateway model ID (from user
input) in log entries instead of the provider-specific
rewritten model name. This ensures accurate logging and
analytics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@bunnyshell

bunnyshell Bot commented Oct 4, 2025 •

Copy link
Copy Markdown

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

Queued actions:

# Action Triggered By
1 ❌ Delete pull request closed

@coderabbitai

coderabbitai Bot commented Oct 4, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Adds initialRequestedModel to capture the original modelInput and updates logging and response payloads in chat.ts to reference this value instead of requestedModel, preserving the original requested model name across routing/normalization.

Changes

Cohort / File(s) Summary
Chat logging and payload fields
apps/gateway/src/chat/chat.ts
Introduced initialRequestedModel from modelInput; replaced requestedModel references with initialRequestedModel in base log entries and response data to retain the original requested model name for auditing/logging. No exported/public API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • feat(logging): add usedModelMapping #769 — Also modifies chat.ts logging fields to preserve original/derived model naming (adds usedModelMapping/usedModelFormatted), overlapping with this PR’s logging-field focus.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly indicates the main change (logging the initial requested model ID) within the gateway scope using the conventional fix(...) prefix, concisely summarizing the PR’s purpose.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch steebchen/save-requested-model-id

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 336fcc6 and 1035443.

📒 Files selected for processing (1)
  • apps/gateway/src/chat/chat.ts (10 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: This is a pure TypeScript project—do not use any or as any unless absolutely necessary
Always use top-level ES imports; never use require or dynamic import()

Files:

  • apps/gateway/src/chat/chat.ts
{apps/api,apps/gateway}/**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

For read queries, use db().query.<table>.findMany() or findFirst()

Files:

  • apps/gateway/src/chat/chat.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Always use top-level import; never use require() or dynamic import()

Files:

  • apps/gateway/src/chat/chat.ts
apps/{gateway,api}/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

apps/{gateway,api}/**/*.ts: Use Hono for HTTP routing in Gateway and API services
Use Zod schemas for request/response validation in server routes

Files:

  • apps/gateway/src/chat/chat.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: lint / run
  • GitHub Check: test / run
  • GitHub Check: e2e-shards (3)
  • GitHub Check: build / run
  • GitHub Check: e2e-shards (1)
  • GitHub Check: generate / run
  • GitHub Check: e2e-shards (2)
  • GitHub Check: e2e-shards (4)
  • GitHub Check: autofix
🔇 Additional comments (3)
apps/gateway/src/chat/chat.ts (3)

409-410: LGTM! Well-placed variable declaration.

The initialRequestedModel variable correctly captures the original user input before any provider-specific transformations. The placement after validation and before routing logic is optimal.


1419-3111: LGTM! Consistent logging updates across all code paths.

All 8 createLogEntry() calls have been consistently updated to use initialRequestedModel, covering all scenarios:

  • Cached responses (streaming and non-streaming)
  • Successful completions (streaming and non-streaming)
  • Error cases (streaming and non-streaming)
  • Canceled requests (streaming and non-streaming)

This ensures the original user-requested model ID is preserved in logs across all execution paths.


3021-3021: LGTM! Error response correctly includes original model ID.

The error response now includes the original user-requested model ID, providing better debugging information and consistency with the logging changes.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@steebchen
steebchen enabled auto-merge October 4, 2025 22:45
@steebchen
steebchen added this pull request to the merge queue Oct 4, 2025
Merged via the queue into main with commit 6ec6fe1 Oct 4, 2025
15 checks passed
@steebchen
steebchen deleted the steebchen/save-requested-model-id branch October 4, 2025 22:54
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