Skip to content

Expose Preview Branch anon key via CLI #3088

Open

Description

@Thorsten-Kd

Is your feature request related to a problem? Please describe.
We're creating preview branches for development through a script on the command line. I am able to retrieve all the preview branch details, like the jwt secret, but I am not able to retrieve the anon key via the CLI. We need the anon key to spin up a development server

Describe the solution you'd like
Ideally I would like to use a command like supabase branches get-api-keys <branch_id> that returns the api keys that we can use to spin up a development server.

Describe alternatives you've considered
I tried using the jwt secret returned by supabase branches get <branch_id> to create an anon key, but I wasn't able to create a working anon key even though I followed the directions here and was able to create a similar anon key than the one that is exposed on the dashboard:
https://stackoverflow.com/questions/74587078/any-way-to-generate-supabase-anon-key-and-jwt-secret-locally

Additional context
We need this to be automated and can't copy the anon key manually from the preview branch dashboard.

Activity

  1. cwharris commented on Nov 25, 2025

    @cwharris

    I'm running in to this because I had hoped the Supabase GitHub integration would be smart enough to sync the public url and anon key to the Vercel deployment associated with the Supabase branch created for the GitHub pull request. I was looking for a way I could hack it together myself, but because we are unable to programatically retrieve the public url and anon key, it appears to be impossible to automate.

    edit:

    after hacking at it for a while, I have Supabase branches and Vercel deployments playing nice together and syncing the appropriate secrets (via the official integrations), but I'll have to examine what exactly I did to get it working. If anyone is interested feel free to ask and I'll see if I can wrangle up some instructions.

  2. Siilwyn commented on Feb 25, 2026

    @Siilwyn

    Anybody figured this one out? We're not using Vercel so got to integrate somehow ...
    Possibly terraform is an option, but having something simpler would be great.

  3. added
    do-not-close
    on Jun 17, 2026
  4. flyinglimao commented on Jul 23, 2026

    @flyinglimao

    supabase branches get <branch-id> -o json outputs the credentials in JSON format:

    {
    "POSTGRES_URL": "...",
    "POSTGRES_URL_NON_POOLING": "...",
    "SUPABASE_ANON_KEY": "...",
    "SUPABASE_DEFAULT_KEY": "...",
    "SUPABASE_JWT_SECRET": "...",
    "SUPABASE_PUBLISHABLE_KEY": "...",
    "SUPABASE_SERVICE_ROLE_KEY": "...",
    "SUPABASE_URL": "..."
    }

    We've been using this in our workflow for months without any issues. Hope this helps!

  5. celine-m-s commented on Sep 3, 2026

    @celine-m-s

    Hey there! I wanted to do the same thing to retrieve the default key but it's obfuscated.

    $ supabase branches get <branch_id> -o json
    {
      "POSTGRES_URL": "",
      "POSTGRES_URL_NON_POOLING": "",
      "SUPABASE_ANON_KEY": "<anon_key_in_clear>",
      "SUPABASE_DEFAULT_KEY": "sb_secret_AAAAA··························",
      "SUPABASE_JWT_SECRET": "<jwt_in_clear>",
      "SUPABASE_PUBLISHABLE_KEY": "sb_publishable_AAAAAAAAAAAAAAAAAAAAAAAA",
      "SUPABASE_SERVICE_ROLE_KEY": "<service_role_in_clear>",
      "SUPABASE_URL": ""
    }
    

    This is a problem to migrate to the new version of keys as we're not supposed to use the SUPABASE_SERVICE_ROLE_KEY anymore.
    Did someone managed to get it in clear?
    Thanks in advance!

  6. flyinglimao commented on Sep 3, 2026

    @flyinglimao

    Hi @celine-m-s
    We ran into the same issue as well. Our current workaround is to retrieve the keys separately with:

    supabase projects api-keys \
      --project-ref <branch-project-ref> \
      --reveal \
      -o json

    supabase branches get <branch> -o json currently returns the publishable key, but the new secret key is masked. Using projects api-keys --reveal with the preview branch's own project ref returns the full key.

    In the JSON output, the default secret key is the entry with:

    {
      "type": "secret",
      "name": "default"
    }

    and its api_key field contains the full sb_secret_... value.

    The same command also returns the publishable keys, so you can select whichever key you need from the output.

    The main thing to watch out for is that --project-ref needs to be the preview branch's own project ref, not the parent project ref.

  7. celine-m-s commented on Sep 9, 2026

    @celine-m-s

    Thank you very much @flyinglimao !!

  8. sayandeep0212 commented on Nov 25, 2026

    @sayandeep0212

    Hi maintainers,

    I'd like to take this on.

    While anon and legacy service_role keys are returned, modern sb_secret_... keys (SUPABASE_DEFAULT_KEY) come back masked as ****** because supabase branches get does not pass reveal: true to the API. supabase projects api-keys already provides a --reveal flag for this purpose.

    Proposal:

    • Add --reveal boolean flag to supabase branches get, matching projects api-keys --reveal.
    • Keep default output masked (reveal: false).
    • When --reveal is provided, pass reveal=true to GET /v1/projects/{ref}/api-keys so secret keys are exposed in full for machine formats (-o json, -o env, -o toml, -o yaml).
    • A 403 on restricted tokens fails with BranchesApiKeysUnexpectedStatusError (no silent fallback to masked values).

    Could you please add the open-for-contribution label to this issue? I have the changes and integration tests prepared and will open a PR once labeled.

  9. sayandeep0212 commented on Nov 25, 2026

    @sayandeep0212

    Hi maintainers,

    I'd like to take this on.

    While anon and legacy service_role keys are returned, modern sb_secret_... keys (SUPABASE_DEFAULT_KEY) come back masked as ****** because supabase branches get does not pass reveal: true to the API. supabase projects api-keys already provides a --reveal flag for this purpose.

    Proposal:

    • Add --reveal boolean flag to supabase branches get, matching projects api-keys --reveal.
    • Keep default output masked (reveal: false).
    • When --reveal is provided, pass reveal=true to GET /v1/projects/{ref}/api-keys so secret keys are exposed in full for machine formats (-o json, -o env, -o toml, -o yaml).
    • A 403 on restricted tokens fails with BranchesApiKeysUnexpectedStatusError (no silent fallback to masked values).

    Could you please add the open-for-contribution label to this issue? I have the changes and integration tests prepared and will reopen the PR once labeled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    do-not-closesupabase/cli✨ Feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions