danny-avila/LibreChat · error · Error

[${req.baseUrl}] Invalid version: ${version}

Error message

[${req.baseUrl}] Invalid version: ${version}

What it means

Thrown by getCurrentVersion while initializing an Assistants API client. The version token (expected as 'v1' or 'v2') is resolved from, in order: the '/v' segment of req.baseUrl, req.body.version (prefixed with 'v'), or the endpoint config's version field. If the resolved value neither starts with 'v' nor is exactly two characters, it is treated as malformed and rejected. This guards the OpenAI-Beta 'assistants=vN' header from carrying a bad value.

Source

Thrown at api/server/controllers/assistants/helpers.js:30

const { getEndpointsConfig } = require('~/server/services/Config');

/**
 * @param {ServerRequest} req
 * @param {string} [endpoint]
 * @returns {Promise<string>}
 */
const getCurrentVersion = async (req, endpoint) => {
  const index = req.baseUrl.lastIndexOf('/v');
  let version = index !== -1 ? req.baseUrl.substring(index + 1, index + 3) : null;
  if (!version && req.body.version) {
    version = `v${req.body.version}`;
  }
  if (!version && endpoint) {
    const endpointsConfig = await getEndpointsConfig(req);
    version = `v${endpointsConfig?.[endpoint]?.version ?? defaultAssistantsVersion[endpoint]}`;
  }
  if (!version?.startsWith('v') && version.length !== 2) {
    throw new Error(`[${req.baseUrl}] Invalid version: ${version}`);
  }
  return version;
};

/**
 * Asynchronously lists assistants based on provided query parameters.
 *
 * Initializes the client with the current request and response objects and lists assistants
 * according to the query parameters. This function abstracts the logic for non-Azure paths.
 *
 * @deprecated
 * @async
 * @param {object} params - The parameters object.
 * @param {object} params.req - The request object, used for initializing the client.
 * @param {object} params.res - The response object, used for initializing the client.
 * @param {string} params.version - The API version to use.
 * @param {object} params.query - The query parameters to list assistants (e.g., limit, order).
 * @returns {Promise<object>} A promise that resolves to the response from the `openai.beta.assistants.list` method call.

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Ensure the request URL contains a clean version segment like /v1 or /v2 (verify req.baseUrl with a log before the call).
  2. Send version as the bare numeric in req.body.version ('1' or '2') so the code can prefix it with 'v'.
  3. Confirm the endpoint has a version set in the endpoints config or a defaultAssistantsVersion fallback for that endpoint key.
  4. If routing through a proxy, rewrite paths so the '/vN' segment is preserved verbatim.

Example fix

// before: POST /api/assistants/v   (trailing /v, malformed)
// after:  POST /api/assistants/v2
Defensive patterns

Strategy: validation

Validate before calling

function resolveVersion(baseUrl, bodyVersion, endpointVersion) {
  const idx = baseUrl.lastIndexOf('/v');
  let v = idx !== -1 ? baseUrl.substring(idx + 1, idx + 3) : null;
  if (!v && bodyVersion) v = `v${bodyVersion}`;
  if (!v && endpointVersion) v = `v${endpointVersion}`;
  if (!v || !/^v\d$/.test(v)) {
    throw new Error(`Refusing request: invalid version '${v}'`);
  }
  return v;
}

Type guard

function isValidAssistantsVersion(v) {
  return typeof v === 'string' && /^v\d$/.test(v);
}

Try / catch

try { await getOpenAIClient({ req, res }); }
catch (e) { if (/Invalid version/.test(e.message)) { return res.status(400).json({ error: 'Unsupported Assistants API version' }); } throw e; }

Prevention

When it happens

Trigger: A request whose baseUrl contains a '/v' fragment that yields a non-conforming substring (e.g. '/v' at the very end, or '/vX' where X is missing), combined with no usable req.body.version and no endpoint config default. Also fires when a caller sends req.body.version as an already-prefixed or malformed string that survives into a branch that does not re-prefix it.

Common situations: Reverse proxy or custom route prefix that rewrites the '/api/assistants/...' path and breaks the '/v' token; clients hitting a stale endpoint URL after an Assistants v1->v2 migration; a misconfigured endpoint record whose version field is empty or non-numeric.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/b8798020ab812eb3. Report an issue: GitHub.