n8n-io/n8n · error · GatewayAuthError
Gateway rejected token: ${status} ${body}
Error message
Gateway rejected token: ${status} ${body} What it means
GatewayAuthError thrown by uploadCapabilities() when the instance-ai gateway returns 401 or 403 for the X-Gateway-Key pairing token. The error has name 'GatewayAuthError', .status, and .body fields. This is an authentication failure at the gateway init endpoint — the pairing token is invalid, expired, or revoked.
Source
Thrown at packages/@n8n/computer-use/src/gateway-client.ts:316
const url = `${this.options.url}/rest/instance-ai/gateway/init`;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
headers.set('X-Gateway-Key', this.apiKey);
const response = await fetch(url, {
method: 'POST',
headers,
body: JSON.stringify({
rootPath: this.dir,
tools,
hostIdentifier: `${os.userInfo().username}@${os.hostname()}`,
toolCategories: this.activeToolCategories,
}),
});
if (!response.ok) {
const text = await response.text();
if (response.status === 401 || response.status === 403) {
throw new GatewayAuthError(response.status, text);
}
throw new Error(`Failed to upload capabilities: ${response.status} ${text}`);
}
// If the server returned a session key, switch to it for all subsequent requests
// n8n wraps controller responses in { data: ... }
const body = (await response.json()) as { data: { ok: boolean; sessionKey?: string } };
if (body.data.sessionKey) {
this.sessionKey = body.data.sessionKey;
logger.debug('Pairing token consumed, switched to session key');
}
logger.debug('Capabilities uploaded', { toolCount: tools.length });
}
private connectSSE(): void {
const url = `${this.options.url}/rest/instance-ai/gateway/events`;
View on GitHub (pinned to 5ac6606e81)
Solutions
- Re-run the pairing flow to obtain a fresh gateway key
- Verify the gateway URL (options.url) matches the target n8n instance
- Confirm Instance AI / MCP gateway is enabled on the n8n server
- Check the n8n server logs for gateway auth rejection details
Defensive patterns
Strategy: validation
Type guard
import { GatewayAuthError } from './gateway-client';
function isGatewayAuthError(e: unknown): e is GatewayAuthError {
return e instanceof GatewayAuthError;
} Try / catch
try {
await gatewayClient.start();
} catch (e) {
if (e instanceof GatewayAuthError) {
// e.status (401 or 403), e.body (server response text)
printAuthFailure(e);
// Re-pair to get a fresh token
await rePairGateway();
} else {
throw e;
}
} Prevention
- Re-pair the gateway if there is a long gap between pairing and use
- Verify the gateway URL matches the target n8n instance before connecting
- Handle GatewayAuthError by triggering a re-pair flow rather than retrying with the same token
When it happens
Trigger: The pairing token (apiKey) is expired, revoked, or was generated for a different instance. The gateway URL points to a different n8n instance. Instance AI / MCP gateway is disabled on the server. The server restarted and invalidated pairing tokens.
Common situations: Long gap between pairing and tool registration causing token expiry, wrong gateway URL in config, instance restart, clipboard copy error on the token.
Related errors
- Failed to upload capabilities: ${response.status} ${text}
- Credential creation failed: ${res.status} ${text}
- No suspended run found for runId: ${this.runId}
- User permanently denied access to ${resource.toolGroup}: ${r
- GATEWAY_CONFIRMATION_REQUIRED::${JSON.stringify({ toolGroup:
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/2858c1968d2e3ac9.
Report an issue: GitHub.