Skip to main content

How to Resolve Cloud Call Error -604101

When invoking Cloud Call APIs (such as security.msgSecCheck, security.imgSecCheck, etc.) in WeChat CloudBase, you may encounter the -604101 error code with the message system error: error code: -604101.

Symptoms

When calling Cloud Call-related APIs, the following error is returned:

{
"errCode": -604101,
"errMsg": "system error: error code: -604101"
}

Or the complete log resembles:

Error: errCode: -604101 | errMsg: openapi.security.msgSecCheck:fail system error: error code: -604101

Causes

Cloud Calls require declaring the permissions of the APIs to be used in the config.json file in the Cloud Function directory. If permissions are not configured correctly, a -604101 error will be returned upon invocation.

Solutions

Step 1: Create or Modify config.json

Create or modify the config.json file in the Cloud Function directory to add the declaration of the required API permissions.

Example file structure:

cloudfunctions/
└── myFunction/
├── index.js
├── package.json
└── config.json # Add this file

Step 2: Configure API Permissions

Declare the required APIs in the permissions.openapi field in config.json:

{
"permissions": {
"openapi": [
"security.msgSecCheck",
"security.imgSecCheck",
"security.mediaCheckAsync"
]
}
}

Common API examples:

API NamePurpose
security.msgSecCheckText content security check
security.imgSecCheckImage content security check
security.mediaCheckAsyncAsynchronous media content security check (recommended)
templateMessage.sendSend template messages
subscribeMessage.sendSend subscription messages

Step 3: Re-upload the Cloud Function

Use WeChat DevTools to re-upload the Cloud Function to apply the permission configuration.

Step 4: Wait for the Cache to Expire

The permission configuration has a cache time of approximately 10 minutes. If errors still occur after uploading, please wait 10 minutes and try again.

Complete Example

config.json:

{
"permissions": {
"openapi": [
"security.msgSecCheck"
]
}
}

index.js:

const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })

exports.main = async (event, context) => {
try {
const result = await cloud.openapi.security.msgSecCheck({
content: event.content
})
return result
} catch (err) {
console.error(err)
return { errCode: err.errCode, errMsg: err.errMsg }
}
}

Considerations

  1. permissions.openapi is an array of strings, and each element is an API name.
  2. The API names must match the API names in the official documentation exactly.
  3. Every time you modify config.json, you must re-upload the Cloud Function.
  4. It is recommended to use security.mediaCheckAsync instead of security.imgSecCheck as a priority.

FAQ

  1. How do I resolve Cloud Call error -604101?
  2. What should I do if a WeChat CloudBase OpenAPI call fails?
  3. What is the reason for security.msgSecCheck returning a -604101 error?
  4. How do I handle permission denial when calling WeChat Open APIs in a Cloud Function?
  5. How do I configure Cloud Call permissions in config.json?
  6. Where do I set the Cloud Call permission configuration?
  7. How long does it take for permissions to take effect after uploading a Cloud Function?
  8. How do I resolve OpenAPI call failed system errors?
  9. How do I write permissions.openapi in a Cloud Function?
  10. What is the permission declaration format for WeChat CloudBase?