{"record":{"id":"02bac56bb5140fb5","repo":"n8n-io/n8n","slug":"credential-creation-failed-res-status-text","errorCode":null,"errorMessage":"Credential creation failed: ${res.status} ${text}","messagePattern":"Credential creation failed: (.+?) (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/@n8n/computer-use/src/gateway-client.ts","lineNumber":478,"sourceCode":"\t\t\tdir: this.dir,\n\t\t\tsecretsBuffer: {\n\t\t\t\tcapture: (k: string, f: string, v: string) => session.captureSecret(k, f, v),\n\t\t\t\tgetFields: (k: string) => session.getSecretFields(k),\n\t\t\t\tclear: (k: string) => session.clearSecrets(k),\n\t\t\t},\n\t\t\tcreateCredential: async (payload: CreateCredentialPayload) => {\n\t\t\t\tconst url = `${instanceUrl}/rest/instance-ai/gateway/credentials`;\n\t\t\t\tconst headers = new Headers();\n\t\t\t\theaders.set('Content-Type', 'application/json');\n\t\t\t\theaders.set('X-Gateway-Key', gatewayKey);\n\t\t\t\tconst res = await fetch(url, {\n\t\t\t\t\tmethod: 'POST',\n\t\t\t\t\theaders,\n\t\t\t\t\tbody: JSON.stringify(payload),\n\t\t\t\t});\n\t\t\t\tif (!res.ok) {\n\t\t\t\t\tconst text = await res.text();\n\t\t\t\t\tthrow new Error(`Credential creation failed: ${res.status} ${text}`);\n\t\t\t\t}\n\t\t\t\tconst body = (await res.json()) as { data: { credentialId: string } };\n\t\t\t\treturn { credentialId: body.data.credentialId };\n\t\t\t},\n\t\t};\n\n\t\tconst resources = await def.getAffectedResources(typedArgs, context);\n\t\tawait this.checkPermissions(resources, decision);\n\n\t\treturn await def.execute(typedArgs, context);\n\t}\n\n\tprivate async checkPermissions(\n\t\tresources: AffectedResource[],\n\t\tdecision?: ResourceDecision,\n\t): Promise<void> {\n\t\tconst { session, confirmResourceAccess, config } = this.options;\n","sourceCodeStart":460,"sourceCodeEnd":496,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/computer-use/src/gateway-client.ts#L460-L496","documentation":"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.","triggerScenarios":"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).","commonSituations":"Duplicate credential name, invalid OAuth2 app configuration in the payload, gateway key expired mid-session, n8n credential encryption key misconfigured on the server.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"function isCredentialCreationError(e: unknown): boolean {\n  return e instanceof Error && e.message.startsWith('Credential creation failed:');\n}","tryCatchPattern":"try {\n  const { credentialId } = await context.createCredential!(payload);\n  return credentialId;\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Credential creation failed:')) {\n    const status = parseInt(e.message.match(/\\d{3}/)?.[0] ?? '0');\n    if (status === 409) {\n      throw new Error('Credential name already exists. Use a unique name.');\n    }\n    throw new Error(`Failed to create credential: ${e.message}`);\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["gateway","credentials","computer-use"],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}