Mihiru Kongahage
11/22/2025, 10:01 AM{"level":50,"time":"2025-11-22T09:40:20.177Z","label":"Permit.io","msg":"[undefined] permit.api.getApiKeyScope(), err: undefined"}
Error creating resource instance: PermitContextError: could not fetch the api key scope in order to set the api context level
I’ve tested this with both Cloud PDP and a local PDP, but the behavior is the same.
SDK Initialization:
const permit = new Permit({
token: process.env.PERMIT_API_KEY || '',
pdp: 'https://cloudpdp.api.permit.io',
timeout: 30000,
apiContext: {
project: "default",
environment: "dev",
},
throwOnError: true,
log: {
level: 'debug',
}
});
Can you clarify what causes this intermittent failure and how to resolve it?Or Weis
11/22/2025, 10:19 AMOr Weis
11/22/2025, 10:20 AMMihiru Kongahage
11/22/2025, 10:23 AMconst permit = new Permit({
token: process.env.PERMIT_API_KEY || '',
pdp: 'http://localhost:7766',
timeout: 30000,
apiContext: {
project: "default",
environment: "dev",
},
throwOnError:true,
log: {
level: 'debug',
}
});Or Weis
11/22/2025, 10:43 AMMihiru Kongahage
11/22/2025, 10:58 AMOr Weis
11/22/2025, 11:01 AMMihiru Kongahage
11/22/2025, 2:58 PMOr Weis
11/22/2025, 3:18 PMOr Weis
11/22/2025, 3:19 PMOr Weis
11/22/2025, 3:20 PMOr Weis
11/22/2025, 3:21 PMOr Weis
11/22/2025, 3:21 PMAsk Inkeep
11/22/2025, 3:21 PMAsk Inkeep
11/22/2025, 3:22 PMgetApiKeyScope(), here are additional recommendations for resolving API access issues with the Node.js SDK:
The SDK attempts to fetch the API key scope during initialization to set the appropriate context level (1) . This process validates your API key and determines its access level (organization, project, or environment) .
For troubleshooting:
1. *Verify your API Key type* - Environment API Keys are recommended for SDK usage (2) . You can check your API key type in the Permit Dashboard under Settings -> API Keys .
2. *Test direct API connectivity* - Try making a direct API call to verify connectivity:
curl -H "Authorization: Bearer <API Key>" https://api.permit.io/v2/facts/{projectKey}/{environmentKey}/users
3. *Consider the API URL configuration* - If you're in a different region, you may need to specify the appropriate API URL:
const permit = new Permit({
token: "[YOUR_API_KEY]",
pdp: "http://localhost:7766",
// the region in which the Permit environment is located
apiUrl: "https://api.eu.permit.io",
}) ;
4. *Review API Logs* - Check the API Log tab under Settings in the Permit Dashboard to see if your requests are reaching the API and what responses are being returned . The Response tab provides valuable error messages for debugging failed API calls .
Since you mentioned this is an intermittent issue with the getApiKeyScope() call failing, I'd like to help our engineers investigate further. Could you please provide:
1. Which Workspace / Project / Env you are using
2. What calls you are performing (as SDK code or CURL)
3. Which PDP version you are running
4. Any relevant logs from your PDPAsk Inkeep
11/22/2025, 3:22 PMMihiru Kongahage
11/22/2025, 3:46 PMOr Weis
11/22/2025, 3:48 PMOr Weis
11/22/2025, 3:48 PMOr Weis
11/22/2025, 3:49 PMMihiru Kongahage
11/22/2025, 4:00 PM