Skip to content

Working around the Edge Function secrets limit

Last edited: 10/14/2026

Edge Functions 项目最多只能存 100 个密钥(见 Functions 限制)。如果你在管理很多第三方服务的凭证,即使你没有做错什么,也可能会达到这个上限——每次 supabase secrets set NAME=VALUE 调用都会占用一个插槽,不管值有多小。

🌐 Edge Functions projects are capped at 100 secrets (see Functions limits). If you're managing credentials for many third-party services, you can hit this cap even though you haven't done anything wrong — each supabase secrets set NAME=VALUE call uses one slot, regardless of how small the value is.

Supabase 今天不会在每个项目上提高这个限制。下面的解决方法可以绕过它——不过下面的每个密钥大小限制仍然适用,所以这并不能绕过所有的限制。

🌐 Supabase doesn't raise this limit on a per-project basis today. The workaround below gets around it — though the per-secret size limit below still applies, so it isn't a way around every constraint.

怎么修 #

🌐 How to fix

  1. 将相关的凭证整理到一个 JSON 对象中,并以单个秘密名称存储:

    supabase secrets set API_KEYS='{"stripe":"sk_live_xxx","sendgrid":"SG.xxx","aws":"xxx"}'

    无论里面嵌套了多少个密钥,这都算作超过 100 个限制的一个秘密。

  2. 在你的函数中用 Deno.env.get() 和 JSON.parse 读回来:

    const = ..('API_KEYS')
    if (!) {
    throw new ('Missing API_KEYS secret')
    }
    const = .()
    const = .
  3. 确认它是用 supabase secrets list 设置的。

这是 Supabase 自己默认密钥使用的相同模式——SUPABASE_PUBLISHABLE_KEYS 和 SUPABASE_SECRET_KEYS 本身就是以相同方式解析的 JSON 字典(参见 环境变量)。

🌐 This is the same pattern Supabase's own default secrets use — SUPABASE_PUBLISHABLE_KEYS and SUPABASE_SECRET_KEYS are themselves JSON dictionaries parsed the same way (see Environment variables).

注意事项 #

🌐 Things to watch for

  • 不支持部分更新。 设置一个新值会替换整个密钥,所以更新一个键意味着要重新设置整个 JSON 块。建议用脚本或 jq 来生成 JSON,而不是手动输入——一个小错误就会让整组键全部失效。

  • 在命令行中引用很快就变得混乱,尤其是在 bash/zsh 之外(例如 Windows shell 不同方式处理单引号字面量)。如果出现这种情况,可以改为从文件加载密钥——这样值不会被 shell 解析,从而避开转义问题:

    supabase secrets set --env-file .env
  • 秘密最大为48 KiB(24,576个字符) (功能限制)。按逻辑分组——例如,每个第三方集成一个秘密——而不是把所有东西合并成一个大块。典型的API密钥(几十到几百个字符)还有足够空间;长期有效的令牌、JWT或证书即使只有几个条目,也可能接近大小上限。

当这不合适时 #

🌐 When this isn't the right fit

当你的数值因行而异时,比如与单个用户或组织相关的秘密,可以考虑使用 Supabase Vault。Vault 会将秘密加密存储在 Postgres 中,而且 100 个秘密的限制不适用。

🌐 Consider Supabase Vault when your values vary by row, such as secrets tied to individual users or organizations. Vault stores encrypted secrets in Postgres, and the 100-secret limit doesn't apply.

从 Edge 函数读取 Vault 秘密需要一次数据库往返,要么是对 security definer 函数的 supabase.rpc() 调用,要么是服务角色查询。这会增加延迟。

🌐 Reading a Vault secret from an Edge Function costs a database round-trip, either supabase.rpc() against a security definer function or a service-role query. That adds latency.

对于一个项目范围内凭据的平铺列表,把它们分组到一个 JSON 密钥里可以避免来回操作。

🌐 For a flat list of project-wide credentials, grouping them into a single JSON secret avoids the round-trip.

额外资源 #

🌐 Additional resources