Skip to content

Comments

UI: STT Evals#44

Open
nishika26 wants to merge 1 commit intomainfrom
feature/stt_eval
Open

UI: STT Evals#44
nishika26 wants to merge 1 commit intomainfrom
feature/stt_eval

Conversation

@nishika26
Copy link
Contributor

@nishika26 nishika26 commented Feb 12, 2026

Targer issue is #42

Summary by CodeRabbit

  • New Features
    • Added API endpoints for speech-to-text (STT) evaluation workflows, enabling users to manage datasets, upload files, run evaluations, and retrieve results.
    • Integrated API key authentication for secure endpoint access.

@nishika26 nishika26 self-assigned this Feb 12, 2026
@nishika26 nishika26 added the enhancement New feature or request label Feb 12, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2026

📝 Walkthrough

Walkthrough

Six new Next.js API route handlers are added to the app/api/evaluations/stt/ directory. These endpoints proxy requests to a backend service, supporting operations for datasets, files, runs, and results. Each handler validates API keys where required, forwards headers, and returns backend responses with status codes preserved.

Changes

Cohort / File(s) Summary
Dataset Routes
app/api/evaluations/stt/datasets/route.ts, app/api/evaluations/stt/datasets/[dataset_id]/route.ts
GET and POST handlers for listing/creating datasets; GET handler for fetching individual dataset by ID. POST requires X-API-KEY header.
Run Routes
app/api/evaluations/stt/runs/route.ts, app/api/evaluations/stt/runs/[run_id]/route.ts
GET and POST handlers for listing/creating runs; GET handler for fetching individual run by ID. POST requires X-API-KEY header.
File Handler
app/api/evaluations/stt/files/route.ts
POST handler for file uploads via form data. Requires X-API-KEY header; returns 401 if missing. Forwards multipart form data to backend and returns response JSON.
Result Handler
app/api/evaluations/stt/results/[result_id]/route.ts
GET handler for fetching individual result by ID. Forwards X-API-KEY header to backend.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 New routes hop into place, so neat,
APIs proxy with practiced feet,
API keys guard the way,
Backend whispers pass today,
STT evals complete!

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'UI: STT Evals' is vague and does not clearly convey what changes were made; it lacks specific details about the actual implementation (API route handlers, proxying, etc.). Consider a more descriptive title that explains the main change, such as 'Add STT evaluation API route handlers' or 'Implement STT evaluation endpoints for dataset and file operations'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 feature/stt_eval

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 10

🤖 Fix all issues with AI agents
In `@app/api/evaluations/stt/datasets/`[dataset_id]/route.ts:
- Around line 20-24: The catch block currently returns an inaccurate error
message ("Failed to fetch config"); update the response in the catch inside
route.ts so the NextResponse.json call uses a message referencing the dataset
(e.g., "Failed to fetch dataset" or include the dataset_id) instead of "config".
Locate the catch block that calls NextResponse.json and replace the error string
to clearly reference the dataset (and optionally include dataset_id or error
details if available) so the returned error message matches the operation
performed.

In `@app/api/evaluations/stt/datasets/route.ts`:
- Around line 56-61: The catch block in the POST handler currently assumes error
has a .message property (console.error and NextResponse.json using
error.message); update the POST catch to normalize the error into a safe string
(e.g., const msg = error instanceof Error ? error.message : String(error)) and
use that safe value in both the console.error and the NextResponse.json details
so we don't access .message on unknown types; look for the catch in the POST
route handler in route.ts and replace direct error.message usage with this
normalized message before returning the response.
- Around line 18-22: The catch block in the route handler currently assumes
`error.message` exists; update the error handling in the catch clause to narrow
the unknown `error` with `if (error instanceof Error)` and use `error.message`
when true, otherwise provide a safe fallback string (e.g., "Unknown error") when
building the NextResponse JSON; locate and update the catch in the evaluation
STT datasets route (the block that returns NextResponse.json({ success: false,
error: error.message, ... })) to implement this instanceof Error narrowing and
fallback.
- Around line 16-17: The handler currently returns NextResponse.json(data) but
does not forward the upstream HTTP status (same bug as runs/route.ts); change
the return to preserve the original response status (and optionally headers) by
returning NextResponse.json(data, { status: response.status /*, headers:
response.headers */ }); locate the variables response and data in route.ts and
update the NextResponse.json call accordingly.

In `@app/api/evaluations/stt/results/`[result_id]/route.ts:
- Line 8: The code uses a NEXT_PUBLIC_ prefixed env var for server-only route
handlers, which leaks to the client; update the backendUrl constant to read a
non-public variable (e.g., process.env.BACKEND_URL) with the existing fallback
('http://localhost:8000') and replace occurrences in this file's backendUrl
declaration (and the same change in the other five route files in this PR) so
the backend URL is read from a server-only env var instead of
NEXT_PUBLIC_BACKEND_URL.
- Around line 20-24: The catch block returns an inaccurate error message
("Failed to fetch config") — update the NextResponse.json call in the route's
catch handler to return a correct message like "Failed to fetch result" (keep
success:false, data:null and status:500) so the error reflects the endpoint's
purpose; apply the same fix to the analogous catch handlers in the
datasets/[dataset_id] and runs/[run_id] routes, locating the places by searching
for NextResponse.json(...) in the catch blocks of those route handlers.

In `@app/api/evaluations/stt/runs/`[run_id]/route.ts:
- Around line 20-24: The catch block in route.ts returns an inaccurate error
message; update the NextResponse.json call inside the catch (where it currently
returns { success: false, error: 'Failed to fetch config', ... }) to reference
the run (e.g., 'Failed to fetch run' or include the run_id) so the error
correctly describes the failed operation; modify the error string passed to
NextResponse.json in that catch block (the code around NextResponse.json)
accordingly.

In `@app/api/evaluations/stt/runs/route.ts`:
- Around line 18-22: The catch blocks currently access error.message on an
unknown-typed catch variable (seen where NextResponse.json is called in the
catch), which breaks TypeScript strict checks; update each catch (including in
app/api/evaluations/stt/runs/route.ts, datasets/route.ts and runs/route.ts) to
safely narrow the error before reading message—e.g. determine const msg = error
instanceof Error ? error.message : String(error) (or JSON.stringify when
appropriate) and pass msg into NextResponse.json instead of error.message so the
code compiles under strict/useUnknownInCatchVariables.
- Around line 56-61: The catch block in the POST handler currently uses
error.message which will throw if error isn't an Error; update the POST catch
block (the try/catch around the request forward) to safely extract a message by
checking if error is an instance of Error and using error.message, otherwise
convert the error to a string (e.g., String(error) or JSON.stringify fallback)
and include that safe message in the NextResponse.json details and the
console.error call so unknown error shapes don't cause a secondary failure.
- Around line 16-17: The GET handler currently returns the backend JSON body but
drops the original HTTP status; update the response to forward the backend
status by returning NextResponse.json(data, { status: response.status }) instead
of NextResponse.json(data). Apply the same change to the analogous GET handler
in datasets/route.ts so both app/api/evaluations/stt/runs/route.ts and
datasets/route.ts forward response.status via NextResponse.json.
🧹 Nitpick comments (6)
app/api/evaluations/stt/results/[result_id]/route.ts (1)

1-1: NextRequest is imported but unused.

The request parameter is typed as Request, not NextRequest. Either use NextRequest as the parameter type or remove the unused import.

Proposed fix
-import { NextResponse, NextRequest } from 'next/server';
+import { NextResponse } from 'next/server';
app/api/evaluations/stt/datasets/[dataset_id]/route.ts (1)

1-1: Unused NextRequest import — same as the other route files.

app/api/evaluations/stt/runs/[run_id]/route.ts (1)

1-1: Unused NextRequest import.

app/api/evaluations/stt/files/route.ts (3)

37-41: Redundant branch — both paths return the identical response.

The if (!response.ok) check returns the exact same expression as the else branch. Remove the conditional.

Proposed fix
-    // Return the response with the same status code
-    if (!response.ok) {
-      return NextResponse.json(data, { status: response.status });
-    }
-
-    return NextResponse.json(data, { status: response.status });
+    return NextResponse.json(data, { status: response.status });

42-42: Avoid explicit any — use proper type narrowing instead.

Typing error as any suppresses useful type safety. Prefer the unknown + instanceof pattern used elsewhere or at minimum keep it unknown.

Proposed fix
-  } catch (error: any) {
+  } catch (error) {
     console.error('Proxy error:', error);
     return NextResponse.json(
-      { error: 'Failed to forward request to backend', details: error.message },
+      { error: 'Failed to forward request to backend', details: error instanceof Error ? error.message : 'Unknown error' },
       { status: 500 }
     );
   }

1-49: Consider extracting a shared proxy utility to reduce duplication across all six route files.

All six route handlers repeat the same pattern: read env var, forward API key, fetch backend, return JSON, catch errors. A small shared helper (e.g., lib/proxy.ts) accepting the path and options would eliminate ~80% of the boilerplate and make error handling/status forwarding consistent in one place.

Comment on lines +20 to +24
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch config', data: null },
{ status: 500 }
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Error message is inaccurate — should reference "dataset", not "config".

Proposed fix
-      { success: false, error: 'Failed to fetch config', data: null },
+      { success: false, error: 'Failed to fetch dataset', data: null },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch config', data: null },
{ status: 500 }
);
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch dataset', data: null },
{ status: 500 }
);
🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/datasets/`[dataset_id]/route.ts around lines 20 - 24,
The catch block currently returns an inaccurate error message ("Failed to fetch
config"); update the response in the catch inside route.ts so the
NextResponse.json call uses a message referencing the dataset (e.g., "Failed to
fetch dataset" or include the dataset_id) instead of "config". Locate the catch
block that calls NextResponse.json and replace the error string to clearly
reference the dataset (and optionally include dataset_id or error details if
available) so the returned error message matches the operation performed.

Comment on lines +16 to +17
const data = await response.json();
return NextResponse.json(data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Backend status not forwarded — same issue as runs/route.ts.

Proposed fix
     const data = await response.json();
-    return NextResponse.json(data);
+    return NextResponse.json(data, { status: response.status });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const data = await response.json();
return NextResponse.json(data);
const data = await response.json();
return NextResponse.json(data, { status: response.status });
🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/datasets/route.ts` around lines 16 - 17, The handler
currently returns NextResponse.json(data) but does not forward the upstream HTTP
status (same bug as runs/route.ts); change the return to preserve the original
response status (and optionally headers) by returning NextResponse.json(data, {
status: response.status /*, headers: response.headers */ }); locate the
variables response and data in route.ts and update the NextResponse.json call
accordingly.

Comment on lines +18 to +22
} catch (error) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

error.message on unknown — same TypeScript issue as runs/route.ts.

Apply the same instanceof Error narrowing here.

🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/datasets/route.ts` around lines 18 - 22, The catch
block in the route handler currently assumes `error.message` exists; update the
error handling in the catch clause to narrow the unknown `error` with `if (error
instanceof Error)` and use `error.message` when true, otherwise provide a safe
fallback string (e.g., "Unknown error") when building the NextResponse JSON;
locate and update the catch in the evaluation STT datasets route (the block that
returns NextResponse.json({ success: false, error: error.message, ... })) to
implement this instanceof Error narrowing and fallback.

Comment on lines +56 to +61
} catch (error) {
console.error('Proxy error:', error);
return NextResponse.json(
{error:'Failed to forward request', details:error.message},
{status:500}
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

error.message on unknown in POST catch block — same fix needed.

🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/datasets/route.ts` around lines 56 - 61, The catch
block in the POST handler currently assumes error has a .message property
(console.error and NextResponse.json using error.message); update the POST catch
to normalize the error into a safe string (e.g., const msg = error instanceof
Error ? error.message : String(error)) and use that safe value in both the
console.error and the NextResponse.json details so we don't access .message on
unknown types; look for the catch in the POST route handler in route.ts and
replace direct error.message usage with this normalized message before returning
the response.

{ params }: { params: Promise<{ result_id: string }> }
) {
const { result_id } = await params;
const backendUrl = process.env.NEXT_PUBLIC_BACKEND_URL || 'http://localhost:8000';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

NEXT_PUBLIC_ prefix exposes the backend URL to the client bundle.

Environment variables prefixed with NEXT_PUBLIC_ are inlined into the client-side JavaScript bundle. Since this is a server-only route handler, use a non-prefixed variable (e.g., BACKEND_URL) to avoid leaking internal infrastructure URLs to the browser. This applies to all six route files in this PR.

🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/results/`[result_id]/route.ts at line 8, The code
uses a NEXT_PUBLIC_ prefixed env var for server-only route handlers, which leaks
to the client; update the backendUrl constant to read a non-public variable
(e.g., process.env.BACKEND_URL) with the existing fallback
('http://localhost:8000') and replace occurrences in this file's backendUrl
declaration (and the same change in the other five route files in this PR) so
the backend URL is read from a server-only env var instead of
NEXT_PUBLIC_BACKEND_URL.

Comment on lines +20 to +24
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch config', data: null },
{ status: 500 }
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Error message is inaccurate — copy-paste artifact.

The error says 'Failed to fetch config' but this endpoint fetches a result, not a config. The same copy-paste error appears in the datasets/[dataset_id] and runs/[run_id] routes as well.

Proposed fix
-      { success: false, error: 'Failed to fetch config', data: null },
+      { success: false, error: 'Failed to fetch result', data: null },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch config', data: null },
{ status: 500 }
);
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch result', data: null },
{ status: 500 }
);
🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/results/`[result_id]/route.ts around lines 20 - 24,
The catch block returns an inaccurate error message ("Failed to fetch config") —
update the NextResponse.json call in the route's catch handler to return a
correct message like "Failed to fetch result" (keep success:false, data:null and
status:500) so the error reflects the endpoint's purpose; apply the same fix to
the analogous catch handlers in the datasets/[dataset_id] and runs/[run_id]
routes, locating the places by searching for NextResponse.json(...) in the catch
blocks of those route handlers.

Comment on lines +20 to +24
} catch (error) {
return NextResponse.json(
{ success: false, error: 'Failed to fetch config', data: null },
{ status: 500 }
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Error message is inaccurate — should reference "run", not "config".

Proposed fix
-      { success: false, error: 'Failed to fetch config', data: null },
+      { success: false, error: 'Failed to fetch run', data: null },
🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/runs/`[run_id]/route.ts around lines 20 - 24, The
catch block in route.ts returns an inaccurate error message; update the
NextResponse.json call inside the catch (where it currently returns { success:
false, error: 'Failed to fetch config', ... }) to reference the run (e.g.,
'Failed to fetch run' or include the run_id) so the error correctly describes
the failed operation; modify the error string passed to NextResponse.json in
that catch block (the code around NextResponse.json) accordingly.

Comment on lines +16 to +17
const data = await response.json();
return NextResponse.json(data);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Backend HTTP status is silently dropped — client always receives 200.

Unlike the [run_id] sub-route (which passes { status: response.status }), this GET handler returns the data without forwarding the backend's status code. A 404 or 403 from the backend will appear as a 200 to the client. The same issue exists in datasets/route.ts GET (Line 17).

Proposed fix
     const data = await response.json();
-    return NextResponse.json(data);
+    return NextResponse.json(data, { status: response.status });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const data = await response.json();
return NextResponse.json(data);
const data = await response.json();
return NextResponse.json(data, { status: response.status });
🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/runs/route.ts` around lines 16 - 17, The GET handler
currently returns the backend JSON body but drops the original HTTP status;
update the response to forward the backend status by returning
NextResponse.json(data, { status: response.status }) instead of
NextResponse.json(data). Apply the same change to the analogous GET handler in
datasets/route.ts so both app/api/evaluations/stt/runs/route.ts and
datasets/route.ts forward response.status via NextResponse.json.

Comment on lines +18 to +22
} catch (error) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

error.message on unknown type will fail TypeScript strict checks.

In TypeScript, the caught error is typed as unknown by default. Accessing .message directly without narrowing will cause a compile error under strict / useUnknownInCatchVariables. This same issue appears in datasets/route.ts Lines 20 and 59, and runs/route.ts Line 59.

Proposed fix
   } catch (error) {
     return NextResponse.json(
-      { success: false, error: error.message, data: null },
+      { success: false, error: error instanceof Error ? error.message : 'Internal server error', data: null },
       { status: 500 }
     );
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
return NextResponse.json(
{ success: false, error: error.message, data: null },
{ status: 500 }
);
} catch (error) {
return NextResponse.json(
{ success: false, error: error instanceof Error ? error.message : 'Internal server error', data: null },
{ status: 500 }
);
}
🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/runs/route.ts` around lines 18 - 22, The catch blocks
currently access error.message on an unknown-typed catch variable (seen where
NextResponse.json is called in the catch), which breaks TypeScript strict
checks; update each catch (including in app/api/evaluations/stt/runs/route.ts,
datasets/route.ts and runs/route.ts) to safely narrow the error before reading
message—e.g. determine const msg = error instanceof Error ? error.message :
String(error) (or JSON.stringify when appropriate) and pass msg into
NextResponse.json instead of error.message so the code compiles under
strict/useUnknownInCatchVariables.

Comment on lines +56 to +61
} catch (error) {
console.error('Proxy error:', error);
return NextResponse.json(
{error:'Failed to forward request', details:error.message},
{status:500}
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Same error.message on unknown issue in the POST catch block.

Proposed fix
   } catch (error) {
     console.error('Proxy error:', error);
     return NextResponse.json(
-      {error:'Failed to forward request', details:error.message},
+      {error:'Failed to forward request', details: error instanceof Error ? error.message : 'Unknown error'},
       {status:500}
     );
   }
🤖 Prompt for AI Agents
In `@app/api/evaluations/stt/runs/route.ts` around lines 56 - 61, The catch block
in the POST handler currently uses error.message which will throw if error isn't
an Error; update the POST catch block (the try/catch around the request forward)
to safely extract a message by checking if error is an instance of Error and
using error.message, otherwise convert the error to a string (e.g.,
String(error) or JSON.stringify fallback) and include that safe message in the
NextResponse.json details and the console.error call so unknown error shapes
don't cause a secondary failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant