sveltejs/kit · error · Error
Invalid remote key: ${key}
Error message
Invalid remote key: ${key} What it means
Remote function endpoints address calls with keys of the form `<id>/<payload>`; split_remote_key splits on the last '/'. If the key contains no '/', it is malformed and Kit cannot determine the remote function id, so it throws.
Source
Thrown at packages/kit/src/runtime/shared.js:349
}
/**
* @param {string} id
* @param {string} payload
*/
export function create_remote_key(id, payload) {
return id + '/' + payload;
}
/**
* @param {string} key
* @returns {{ id: string; payload: string }}
*/
export function split_remote_key(key) {
const i = key.lastIndexOf('/');
if (i === -1) {
throw new Error(`Invalid remote key: ${key}`);
}
return {
id: key.slice(0, i),
payload: key.slice(i + 1)
};
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Fix the caller to pass the full `<id>/<payload>` key produced by Kit's remote-function client
- If calling internals directly, append the payload segment (use '/' even when payload is empty)
- Inspect request URLs/logs to find who is stripping part of the key
- Upgrade Kit if you suspect a routing bug, and open an issue with a repro
Example fix
// before
split_remote_key('myQuery');
// after
split_remote_key('src/lib/remote.svelte.js/myQuery/'); Defensive patterns
Strategy: validation
Validate before calling
const buildRemoteKey = (id, payload = '') => `${id}/${payload}`;
const isValidRemoteKey = (key) => typeof key === 'string' && key.includes('/'); Type guard
const isRemoteKey = (v) => typeof v === 'string' && v.lastIndexOf('/') !== -1; Try / catch
try {
const { id, payload } = split_remote_key(key);
} catch (e) {
if (e.message.startsWith('Invalid remote key')) {
console.error('Key must be <id>/<payload>:', key);
} else throw e;
} Prevention
- Only construct remote keys with Kit's own client APIs
- Log full request URLs to catch proxies stripping query segments
- Never hand-edit remote-function URLs
- Add integration tests that exercise remote endpoints end-to-end
When it happens
Trigger: A request arrives at the remote endpoint machinery with a key lacking a '/' — caused by hand-built requests to internal remote endpoints, corrupted/modified query strings, or programmatic callers that pass the wrong string to split_remote_key.
Common situations: Custom code or tests invoking internal Kit APIs with a bare id; proxies stripping query parameters; browser extensions rewriting URLs.
Related errors
- ${keypath} option must be an absolute path, if specified. Se
- ${keypath} option must not end with '/'. See https://svelte.
- ${keypath} must be a valid origin (e.g. 'https://my-site.com
- ${keypath} must be a valid origin — only 'http' and 'https'
- Could not get the request store.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/14064ebb80d42cb8.
Report an issue: GitHub.