# Marketstack: agents start here

Steps for AI coding agents that add Marketstack to a project.

## 1. Get an API key

A person creates the account: an agent cannot sign up. Sign up at https://app.apilayer.com/signup/marketstack/ and subscribe to Marketstack. The Free plan includes 100 requests / month and needs no credit card.

Copy the API key from the APILayer dashboard and give it to the agent as an environment variable (step 2).

## 2. Keep the key out of code

Read the key from an environment variable named `APILAYER_ACCESS_KEY`. Do not write the key into source code, commit it to git, or paste it into a chat.

Call Marketstack from server code. The key travels in the request URL, so a request sent from a browser shows the key to every visitor.

```
# add .env to .gitignore
APILAYER_ACCESS_KEY=your_api_key
```

## 3. Make the first request

- Base URL: `https://api.apilayer.net/marketstack/v2`
- Auth: `access_key` query parameter
- Formats: JSON
- Endpoints:
  - `/eod` End-of-day data
  - `/intraday` Intraday data

```sh
curl "https://api.apilayer.net/marketstack/v2/eod?access_key=$APILAYER_ACCESS_KEY&symbols=AAPL"
```

## 4. Check the plan before you use a feature

Each plan adds features to the plan before it. Check that the account's plan includes a feature before writing code that uses it.

| Plan | Requests / month | Adds |
|---|---|---|
| Free | 100 | HTTPS Encryption, End-of-Day stock data, Historical data availability: 1 year, Stock ticker information, Stock exchanges info, Splits & dividends data, Currencies & timezones |
| Starter | 10,000 | Historical data availability: 10 years, Intraday data (US), Stock market indices, Bonds data, ETF holdings data, Commercial use allowed, Standard support included |
| Professional | 100,000 | Historical data availability: 15+ years, Real-time stock prices, Commodity prices |
| Enterprise | 500,000 | Company ratings, Company financial statements, Company details / facts |

Prices: https://apilayer.com/products/marketstack/#pricing

## 5. Use the machine-readable docs

- Marketstack documentation: https://docs.apilayer.com/apilayer/docs/marketstack
- APILayer llms.txt: https://apilayer.com/llms.txt
