Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

fix(api): accept research paper ids that contain a raw slash (#5635)

Karan Lokchandani9965df2b1d4e
diff --git a/apps/api/src/__tests__/routes/research-keyless.routes.test.ts b/apps/api/src/__tests__/routes/research-keyless.routes.test.ts
index 91712b482..7d589aeb4 100644
--- a/apps/api/src/__tests__/routes/research-keyless.routes.test.ts
+++ b/apps/api/src/__tests__/routes/research-keyless.routes.test.ts
@@ -35,8 +35,8 @@ async function appWithResearchGate(flag: string | undefined) {
const reached = (_req: express.Request, res: express.Response) =>
res.status(200).json({ reachedController: true });
router.get("/papers", reached);
- router.get("/papers/:id/similar", reached);
- router.get("/papers/:id", reached);
+ router.get("/papers/*id/similar", reached);
+ router.get("/papers/*id", reached);
app.use(
"/v2/search/research",
@@ -186,6 +186,8 @@ describe("keyless Research Index requests through the auth middleware", () => {
"/v2/search/research/papers/2401.00001",
"/v2/search/research/papers/2401.00001?query=attention",
"/v2/search/research/papers/2401.00001/similar",
+ "/v2/search/research/papers/doi:10.1101/2025.07.31.667845?query=x",
+ "/v2/search/research/papers/doi:10.1101/2025.07.31.667845/similar",
]) {
const response = await request(app).get(path);
diff --git a/apps/api/src/__tests__/routes/research-paper-id.routes.test.ts b/apps/api/src/__tests__/routes/research-paper-id.routes.test.ts
new file mode 100644
index 000000000..2baf4526d
--- /dev/null
+++ b/apps/api/src/__tests__/routes/research-paper-id.routes.test.ts
@@ -0,0 +1,64 @@
+import express from "express";
+import request from "supertest";
+import { createResearchRouter } from "../../controllers/v2/research-proxy";
+
+const upstreamCalls: string[] = [];
+
+vi.mock("../../lib/research-upstream", () => ({
+ fetchResearchUpstream: async (options: { path: string }) => {
+ upstreamCalls.push(options.path);
+ return {
+ status: 200,
+ ok: true,
+ headers: new Headers(),
+ text: async () => JSON.stringify({ success: true, results: [] }),
+ };
+ },
+}));
+
+vi.mock("../../services/logging/log_job", () => ({
+ logRequest: async () => {},
+ logResearchEndpoint: async () => {},
+}));
+
+vi.mock("../../lib/keyless", () => ({
+ chargeKeylessCredits: async () => {},
+}));
+
+vi.mock("../../lib/index-daily-limit", () => ({
+ reserveIndexCalls: async () => ({ ok: true, release: async () => {} }),
+ indexDailyLimitRefusal: () => {},
+}));
+
+const app = express();
+app.use((req: any, _res, next) => {
+ req.auth = { team_id: "team-test", plan: "standard" };
+ req.acuc = { api_key_id: 4 };
+ next();
+});
+app.use("/v2/search/research", createResearchRouter());
+
+beforeEach(() => {
+ upstreamCalls.length = 0;
+});
+
+it.each([
+ [
+ "doi:10.1101/2025.07.31.667845?query=x",
+ "/v2/research/papers/doi%3A10.1101%2F2025.07.31.667845",
+ ],
+ [
+ "doi:10.1101%2F2025.07.31.667845?query=x",
+ "/v2/research/papers/doi%3A10.1101%2F2025.07.31.667845",
+ ],
+ [
+ "doi:10.1101/2025.07.31.667845/similar?intent=x",
+ "/v2/research/papers/doi%3A10.1101%2F2025.07.31.667845/similar",
+ ],
+ ["pmid:40000000/", "/v2/research/papers/pmid%3A40000000"],
+])("forwards paper id %s as one encoded segment", async (path, upstream) => {
+ const res = await request(app).get(`/v2/search/research/papers/${path}`);
+
+ expect(res.statusCode).toBe(200);
+ expect(upstreamCalls).toEqual([upstream]);
+});
diff --git a/apps/api/src/controllers/v2/__tests__/research-timeouts.test.ts b/apps/api/src/controllers/v2/__tests__/research-timeouts.test.ts
index dfadafae0..fd683a8a3 100644
--- a/apps/api/src/controllers/v2/__tests__/research-timeouts.test.ts
+++ b/apps/api/src/controllers/v2/__tests__/research-timeouts.test.ts
@@ -119,9 +119,9 @@ describe("research upstream timeouts", () => {
{
name: "similar papers",
router: () => createResearchRouter(),
- path: "/papers/:id/similar",
+ path: "/papers/*id/similar",
query: { intent: "related work" },
- params: { id: "paper-1" },
+ params: { id: ["paper-1"] },
timeoutMs: 10_000,
},
{
@@ -149,8 +149,8 @@ describe("research upstream timeouts", () => {
{ name: "inspect", query: {}, timeoutMs: 5_000 },
{ name: "read", query: { query: "summarize methods" }, timeoutMs: 120_000 },
])("uses the paper $name timeout", async ({ query, timeoutMs }) => {
- await callRoute(createResearchRouter(), "/papers/:id", query, {
- id: "paper-1",
+ await callRoute(createResearchRouter(), "/papers/*id", query, {
+ id: ["paper-1"],
});
expect(mocks.fetchResearchUpstream).toHaveBeenCalledWith(
diff --git a/apps/api/src/controllers/v2/research-proxy.ts b/apps/api/src/controllers/v2/research-proxy.ts
index f6afd65c7..d60110f8d 100644
--- a/apps/api/src/controllers/v2/research-proxy.ts
+++ b/apps/api/src/controllers/v2/research-proxy.ts
@@ -568,6 +568,10 @@ function createResearchController(
};
}
+function paperId(req: Request) {
+ return (req.params.id as string[]).filter(Boolean).join("/");
+}
+
export function createResearchRouter(options: { legacy?: boolean } = {}) {
const router = express.Router();
@@ -609,7 +613,7 @@ export function createResearchRouter(options: { legacy?: boolean } = {}) {
);
router.get(
- "/papers/:id/similar",
+ "/papers/*id/similar",
wrap(
createResearchController(
similarPapersSchema,
@@ -619,9 +623,9 @@ export function createResearchRouter(options: { legacy?: boolean } = {}) {
table: "research_related_papers",
action: "similarPapers",
targetHint: (params, req) =>
- `${req.params.id}: ${String(params.intent)}`,
+ `${paperId(req)}: ${String(params.intent)}`,
upstreamPath: (_params, req) =>
- `/v2/research/papers/${encodeURIComponent(req.params.id)}/similar`,
+ `/v2/research/papers/${encodeURIComponent(paperId(req))}/similar`,
timeoutMs: SIMILAR_PAPERS_TIMEOUT_MS,
billAs: "search",
},
@@ -631,7 +635,7 @@ export function createResearchRouter(options: { legacy?: boolean } = {}) {
);
router.get(
- "/papers/:id",
+ "/papers/*id",
wrap(async (req: Request, res: Response) => {
const authedReq = req as RequestWithAuth<any, any, any>;
const parsed = paperSchema.safeParse(req.query);
@@ -643,9 +647,9 @@ export function createResearchRouter(options: { legacy?: boolean } = {}) {
kind: isRead ? "research_paper_read" : "research_paper_inspect",
table: isRead ? "research_paper_reads" : "research_paper_inspects",
action: isRead ? "readPaper" : "inspectPaper",
- targetHint: (_params, request) => request.params.id,
+ targetHint: (_params, request) => paperId(request),
upstreamPath: (_params, request) =>
- `/v2/research/papers/${encodeURIComponent(request.params.id)}`,
+ `/v2/research/papers/${encodeURIComponent(paperId(request))}`,
timeoutMs: isRead ? PAPER_READ_TIMEOUT_MS : PAPER_INSPECT_TIMEOUT_MS,
billAs: "scrape",
},
diff --git a/apps/api/src/lib/research-keyless.ts b/apps/api/src/lib/research-keyless.ts
index e1b18b59c..c66c8ed80 100644
--- a/apps/api/src/lib/research-keyless.ts
+++ b/apps/api/src/lib/research-keyless.ts
@@ -10,11 +10,8 @@ function researchKeylessOperation(
const rest = segments.slice(papersIndex + 1);
if (rest.length === 0) return "search";
- if (rest.length === 1) {
- return req.query?.query === undefined ? "inspect" : "read";
- }
- if (rest.length === 2 && rest[1] === "similar") return "similar";
- return null;
+ if (rest.length > 1 && rest.at(-1) === "similar") return "similar";
+ return req.query?.query === undefined ? "inspect" : "read";
}
export function isResearchKeylessDisabled(req: Request): boolean {