n8n-io/n8n · error · Error
Credential creation failed: ${res.status} ${text}
Error message
Credential creation failed: ${res.status} ${text} What it means
Thrown inside the createCredential callback (registered on the ToolContext) when the gateway credential creation endpoint returns a non-OK response. This happens during tool execution when a tool needs to create an OAuth credential through the n8n instance's /rest/instance-ai/gateway/credentials endpoint.
Source
Thrown at packages/@n8n/computer-use/src/gateway-client.ts:478
dir: this.dir,
secretsBuffer: {
capture: (k: string, f: string, v: string) => session.captureSecret(k, f, v),
getFields: (k: string) => session.getSecretFields(k),
clear: (k: string) => session.clearSecrets(k),
},
createCredential: async (payload: CreateCredentialPayload) => {
const url = `${instanceUrl}/rest/instance-ai/gateway/credentials`;
const headers = new Headers();
headers.set('Content-Type', 'application/json');
headers.set('X-Gateway-Key', gatewayKey);
const res = await fetch(url, {
method: 'POST',
headers,
body: JSON.stringify(payload),
});
if (!res.ok) {
const text = await res.text();
throw new Error(`Credential creation failed: ${res.status} ${text}`);
}
const body = (await res.json()) as { data: { credentialId: string } };
return { credentialId: body.data.credentialId };
},
};
const resources = await def.getAffectedResources(typedArgs, context);
await this.checkPermissions(resources, decision);
return await def.execute(typedArgs, context);
}
private async checkPermissions(
resources: AffectedResource[],
decision?: ResourceDecision,
): Promise<void> {
const { session, confirmResourceAccess, config } = this.options;
View on GitHub (pinned to 5ac6606e81)
Solutions
- Check the status code and response text in the error message
- Use a unique credential name to avoid 409 conflicts
- Verify the CreateCredentialPayload fields match the expected schema
- Re-pair the gateway if the key expired during the session
Defensive patterns
Strategy: try-catch
Type guard
function isCredentialCreationError(e: unknown): boolean {
return e instanceof Error && e.message.startsWith('Credential creation failed:');
} Try / catch
try {
const { credentialId } = await context.createCredential!(payload);
return credentialId;
} catch (e) {
if (e instanceof Error && e.message.startsWith('Credential creation failed:')) {
const status = parseInt(e.message.match(/\d{3}/)?.[0] ?? '0');
if (status === 409) {
throw new Error('Credential name already exists. Use a unique name.');
}
throw new Error(`Failed to create credential: ${e.message}`);
}
throw e;
} Prevention
- Use unique credential names to avoid 409 conflicts
- Validate the CreateCredentialPayload fields before submission
- Re-pair the gateway if session key may have expired mid-execution
When it happens
Trigger: Gateway credential endpoint returns 400 (invalid credential payload, missing required fields), 401/403 (gateway key expired during tool execution), 409 (credential name already exists), 500 (server-side credential store error).
Common situations: Duplicate credential name, invalid OAuth2 app configuration in the payload, gateway key expired mid-session, n8n credential encryption key misconfigured on the server.
Related errors
- Gateway rejected token: ${status} ${body}
- Failed to upload capabilities: ${response.status} ${text}
- LangSmithTelemetry creates its own tracer — do not use .otlp
- No suspended run found for runId: ${this.runId}
- Invalid resume payload: ${parseResult.error}
AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12).
Data as JSON: /api/errors/02bac56bb5140fb5.
Report an issue: GitHub.