Built into AlgoGPFree

How to get a Alpaca API key

An Alpaca API key is a pair: a public key id and a secret key. Paper and live accounts each have their own pair. This guide creates a paper key first, which is what you should trade with until a strategy has earned real money.

About 10 minutes 5 steps Checked October 2026

Before you start

  • An email address and a phone for two-factor authentication
  • Nothing to fund: paper trading needs no deposit
  • For live keys only: a completed and approved brokerage application

Create your Alpaca API key

  1. 1

    Create an Alpaca account

    Go to alpaca.markets and sign up with your email. Verify the address from the confirmation email. You can stop here for paper trading; the brokerage application is only needed for live keys.

  2. 2

    Switch to your paper account

    Open the dashboard at app.alpaca.markets. Use the account switcher at the top left to select your Paper account (its id starts with PA).

  3. 3

    Generate the key pair

    On the paper account home page find the API Keys panel on the right and click Generate New Keys (or Regenerate if a pair exists; that revokes the old one).

  4. 4

    Copy both values immediately

    Copy the Key (key id, starts with PK for paper) and the Secret. The secret is shown only once; if you lose it, regenerate the pair and update everywhere it is used.

  5. 5

    Repeat for live trading later

    Once your brokerage account is approved and funded, switch to the Live account and generate a separate pair there (key ids start with AK). Live keys only work against api.alpaca.markets.

Test the key

Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.

curl -s https://paper-api.alpaca.markets/v2/account \
  -H "APCA-API-KEY-ID: $ALPACA_API_KEY_ID" \
  -H "APCA-API-SECRET-KEY: $ALPACA_API_SECRET_KEY"
A JSON object with status: "ACTIVE", cash and equity means the key works. 401/403 usually means a live key against the paper URL or vice versa.

Add the key to your AlgoGP project

  1. 1

    Open your project’s APIs & keys tab

    Open the strategy project, select APIs & keys, and under Platforms choose Alpaca.

  2. 2

    Paste each value

    Paste the values into ALPACA_API_KEY_ID and ALPACA_API_SECRET_KEY and click Save. Values are encrypted at rest, never shown again and never written into code or exports.

  3. 3

    Run locally with the same names

    Exported projects read the same names from .env (copy .env.example). Keep .env out of version control.

ALPACA_API_KEY_ID=paste-your-value-here
ALPACA_API_SECRET_KEY=paste-your-value-here
# ALPACA_BASE_URL=
.env for local runs

Keep the key safe

  • Never paste the secret into code, a notebook you share, or config.json. Store it in AlgoGP Keys & secrets or a local .env that is git-ignored.
  • Use paper keys for development. Only put live keys on the machine that actually runs live.py.
  • If a secret leaks, click Regenerate in the dashboard at once: the old pair stops working immediately.

Troubleshooting

401 Unauthorized
Wrong key id or secret, or a regenerated pair. Copy both again.
403 Forbidden
Paper key against the live URL (or the reverse), or the account is not yet approved for live trading.
422 on an order
The order itself is invalid: e.g. a fractional short, a crypto order with day time-in-force, or insufficient buying power.
No data for a stock
The free data plan uses the IEX feed; thinly traded symbols can have gaps. Request feed=iex explicitly.

Frequently asked questions

Why can I not see my Alpaca secret key again?

Alpaca shows the secret once, at generation time, and does not store a retrievable copy. Regenerate the pair to get a new secret.

Do paper and live trading use the same Alpaca API key?

No. Each account has its own key pair and base URL. Paper key ids start with PK, live with AK.

Does the Alpaca key also work for market data?

Yes. The same headers authenticate data.alpaca.markets, within the limits of your data plan.

Build an Alpaca trading bot in minutes

Describe the strategy in plain English, backtest it on years of data, then export Python that already talks to Alpaca: paper, sandbox and live modes, keys handled for you.

  • Generated adapter for Alpaca orders and balances
  • Backtests with costs, slippage and walk-forward checks
  • Paper first; live trading only after you opt in

Free plan, no card required.

How the Alpaca API works

AlgoGP is not affiliated with Alpaca. Menus get renamed from time to time; if a label differs, the official documentation has the current path.