Skip to content
CLI

Authentication

Log in, manage tokens, and control which credentials and API the CLI uses.

The CLI sends a bearer token with every API request. You can log in once on your machine and let the CLI store the token, or set SCRAPELY_TOKEN in CI. This page covers the login methods, where credentials are stored, and the order in which the CLI resolves the token and the API URL.

Log in

.bash
scrapely login

scrapely auth login does the same thing.

OptionDescription
-m, --method <method>browser, console, or manual. Any other value is an error.
-t, --token <token>Log in with this token without prompting

On an interactive terminal with neither option, the CLI asks you to choose a method:

MethodWhat happens
browserThe CLI starts a one-shot server on 127.0.0.1, opens the dashboard in your browser, and asks you to approve the CLI. The dashboard sends a token back to the local server. The browser has 5 minutes to complete the flow. If it fails, the CLI asks you to paste a token instead.
consoleThe CLI opens the dashboard. Copy an API key from Settings → API & Integrations and paste it at the prompt.
manualThe CLI asks you to paste a token. Input is masked.

On a terminal that isn't interactive, login without --token uses the console method. Use --token or SCRAPELY_TOKEN in scripts.

If you are already logged in, login asks whether to log in with a different account. --token skips that question.

The CLI validates the token with GET /v2/users/me, then writes the token, the API URL it used, and your user details to ~/.scrapely/credentials.json.

Browser tokens and API keys

The two kinds of token behave differently:

  • Browser login stores an OAuth access token. It expires, by default after 24 hours, and then commands fail with an authentication error until you log in again. It can't read or reset your API key.
  • API keys from Settings → API & Integrations don't expire. Use one for CI, servers, and anything long-running, with scrapely login --token or SCRAPELY_TOKEN.

scrapely login accepts any API key, including a scoped key you created under Settings → API & Integrations → API keys: it only checks the key with GET /v2/users/me. Commands then succeed or fail according to the key's scopes. For CI, prefer a scoped key, for example actors:build + actors:read for deploys. See API keys & permissions.

Check the account

.bash
scrapely info

info fetches your account from the API and prints the username, email, user ID, plan, and the API URL in use. When the token in use is the saved login, it also refreshes the cached user details in credentials.json. A SCRAPELY_TOKEN for another account doesn't overwrite them.

ResultOutputExit code
The API accepts the tokenThe account details0
The API rejects the token (401 or 403)The API at … rejected the token (HTTP …). If the token came from SCRAPELY_TOKEN, it says so.1
Any other HTTP errorFailed to fetch account info (HTTP …)1
The API can't be reachedAfter a few seconds, the account saved at login, marked as possibly stale, if the saved login is the token in use. Otherwise Could not reach the API at ….0 with the saved account, 1 otherwise

To print the token the CLI uses, for example to pass it to another tool:

.bash
scrapely auth token

auth token prints SCRAPELY_TOKEN if it is set, and otherwise the saved token. It fails when neither exists. Treat its output as a secret: it gives access to your account.

Log out

.bash
scrapely logout

scrapely auth logout does the same thing. Both empty ~/.scrapely/credentials.json. If no token is stored, they print Not logged in.

Logging out does not revoke the token. To invalidate an API key, reset it in the dashboard or call POST /v2/api-keys/reset with your API key. A browser login token expires on its own.

The auth group

CommandPurpose
scrapely auth loginSame as scrapely login, with the same options
scrapely auth logoutSame as scrapely logout
scrapely auth tokenPrint the token in use (SCRAPELY_TOKEN or the saved one)

Credentials and precedence

The CLI keeps its state in ~/.scrapely/. Both files are written with mode 0600.

FileContents
credentials.jsonToken, API URL, and cached user details
secrets.jsonLocal secrets for scrapely run. See Secrets.

The token comes from the first of:

  1. SCRAPELY_TOKEN
  2. The token saved in ~/.scrapely/credentials.json

The API URL comes from the first of:

  1. SCRAPELY_API_BASE_URL
  2. SCRAPELY_API_URL
  3. The API URL saved in ~/.scrapely/credentials.json
  4. The default, https://api.scrape.ly (production)

SCRAPELY_TOKEN wins over the saved login, so a key set in CI or in your shell is used even on a machine where you ran scrapely login. Unset it to use the saved login again. The API URL variables likewise win over the saved URL.

The dashboard (console) URL used in printed links, by login -m console, push --open, and task publish, comes from the API URL:

API URLDashboard URL
https://api.scrape.lyhttps://my.scrape.ly
https://api-staging.scrape.lyhttps://my-staging.scrape.ly
api.<domain>my.<domain>
api-<name>.<domain>my-<name>.<domain>
Any other hostThe API URL itself

The scheme and port are kept. SCRAPELY_WEB_URL overrides the derived URL. You only need it when your dashboard isn't on the matching my host.

Commands that need authentication fail with You are not logged in. Call "scrapely login" first. when no token is available. actors search and templates ls work without logging in.

CI and other non-interactive use

Set an API key in the environment. Don't run scrapely login in the pipeline.

.bash
export SCRAPELY_API_URL=https://api.scrape.ly
export SCRAPELY_TOKEN=<your API key>
scrapely push --wait-for-finish 600

In GitHub Actions:

.yaml
- name: Deploy
  env:
    SCRAPELY_API_URL: https://api.scrape.ly
    SCRAPELY_TOKEN: ${{ secrets.SCRAPELY_TOKEN }}
  run: scrapely push --wait-for-finish 600

Keep the key in your CI provider's secret store, never in the repository. Pass -y to delete commands so nothing waits on a prompt. More pipeline examples are in Config & troubleshooting.

Tokens inside an Actor container

The scrapely actor runtime commands resolve credentials differently, because the platform gives each run its own environment.

The token comes from the first of ACTOR_TOKEN, APIFY_TOKEN, SCRAPELY_TOKEN, and the saved token. The API URL comes from the first of APIFY_API_BASE_URL, SCRAPELY_API_BASE_URL, SCRAPELY_API_URL, and the saved API URL.

If any of those API URL variables is set, the saved token is never used. A container that has an API URL but no token can't act with the account saved on the machine. See Actor runtime.

What's next