Skip to main content
Make your first REST call from a server. By the end you have a key in your environment, a working GET /v2/snapshot?symbol=AAPL, and code that reads both the success and error envelopes.
1

Create an API key

Open the keys page at https://stockcontext.com/dashboard/keys, create a key, and copy it before you close the dialog. The raw secret is shown once. Keys start with sctx_ and travel in the X-API-Key header. New keys start on the Free plan: search, coverage, snapshot, and valuation; see plans and limits for the rest.
Keep StockContext keys server-side only. Never put them in frontend code, browser bundles, public repos, logs, screenshots, support chats, or prompts.
2

Set your environment

export STOCKCONTEXT_API_BASE_URL="https://api.stockcontext.com"
export STOCKCONTEXT_API_KEY="<your_stockcontext_api_key>"
3

Make the first call

/v2/snapshot is the best first call for most apps: it returns quote, performance, 52-week range, quick valuation, sector, and industry in one response.
curl -sS "$STOCKCONTEXT_API_BASE_URL/v2/snapshot?symbol=AAPL" \
  -H "X-API-Key: $STOCKCONTEXT_API_KEY"
4

Read the success envelope

Success is always wrapped in data. The response below is trimmed; the live payload also carries a full performance block, a range_52w block, and more fundamentals_quick fields. The response model documents the wrapper in full.
GET /v2/snapshot?symbol=AAPL (trimmed)
{
  "data": {
    "symbol": "AAPL",
    "name": "Apple Inc",
    "currency": "USD",
    "as_of": "2026-06-08T13:07:36Z",
    "freshness": "end_of_day",
    "market_status": "closed",
    "cache_age_seconds": 0,
    "quote": {
      "price": 308.73,
      "change_abs": 1.39,
      "change_pct": 0.45,
      "previous_close": 307.34,
      "volume": 65310502
    },
    "range_52w": {
      "high": 316.94,
      "low": 194.3,
      "position_pct": 92.2,
      "drawdown_from_high_pct": -3.03
    },
    "asset_type": "stock",
    "fundamentals_quick": {
      "market_cap_usd": 4512101567600,
      "pe_ttm": { "value": 36.81, "vs_5y": "near_5y_high" },
      "fcf_yield_pct": 2.86,
      "dividend_yield_pct": 0.35
    },
    "sector": "Technology",
    "industry": "Consumer Electronics"
  }
}
The headline multiples are objects, not bare numbers. On /v2/snapshot, pe_ttm, ps_ttm, pb, and ev_ebitda_ttm each computable value ships as { value, vs_5y? } — read the number at pe_ttm.value. fcf_yield_pct, dividend_yield_pct, the ttm_* fields, shares_outstanding, and beta_5y_weekly stay flat; market_cap_usd and enterprise_value_usd are flat integers.fundamentals_quick.pe_ttm.vs_5y bands the ratio within the symbol’s own five-year history (near_5y_low, below_5y_median, near_5y_median, above_5y_median, near_5y_high, or the _3y_ variants). It is not a cheapness verdict and not a peer comparison. vs_5y is omitted when the history is too thin or the multiple is non-positive; a negative P/E keeps its value at .value and carries a caveat such as negative_earnings_period.Read these before you show or cache the result:
  • data.symbol is the resolved ticker.
  • data.freshness is one of intraday, end_of_day, stale, degraded, or unsupported. See freshness.
  • data.market_status is open or closed.
  • data.as_of is the upstream timestamp when available, otherwise generation time, always UTC ISO-8601.
  • cache_age_seconds is how long the served data has been cached; 0 means freshly computed.
Every success envelope carries freshness, market_status, as_of, and cache_age_seconds. _usd fields are whole U.S. dollars and _pct fields are percentages, not decimals; units and fields covers every convention.
5

Handle the error envelope

Failures are always wrapped in error. Retry only when error.retryable is true.
{
  "error": {
    "code": "RATE_LIMITED",
    "message": "Rate limit exceeded. Please slow request rate and retry.",
    "retryable": true
  }
}
The example above (RATE_LIMITED) is retryable; 503 UPSTREAM_UNAVAILABLE and 503 AUTH_UPSTREAM_UNAVAILABLE are too. The four errors below are not — fix the cause before you call again:
CodeHTTPFix
UNAUTHORIZED401Set a valid key in X-API-Key.
PLAN_UPGRADE_REQUIRED403The route needs Starter or Builder.
SYMBOL_INVALID400Symbol must match the ticker grammar.
SYMBOL_UNKNOWN404Resolve the ticker with /v2/search.
Successful responses carry X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset; a 429 carries them too, plus Retry-After in seconds. Other error responses do not include them, so read your budget from successes. The full table and retry policy live on the error codes page.

Optional fit checks

Run these before you store a user-entered symbol or kick off batch work.
# Resolve a company name to symbols.
curl -sS "$STOCKCONTEXT_API_BASE_URL/v2/search?query=apple" \
  -H "X-API-Key: $STOCKCONTEXT_API_KEY"

# Confirm the symbol is supported and see its asset type.
curl -sS "$STOCKCONTEXT_API_BASE_URL/v2/coverage?symbol=AAPL" \
  -H "X-API-Key: $STOCKCONTEXT_API_KEY"

Call it from code

Both clients check the envelope before the HTTP status, because a 4xx/5xx still carries a structured error. Keep the key server-side; never ship it to the browser.
snapshot.py
import os

import httpx

base_url = os.environ.get("STOCKCONTEXT_API_BASE_URL", "https://api.stockcontext.com")
api_key = os.environ["STOCKCONTEXT_API_KEY"]

with httpx.Client(
    base_url=base_url,
    headers={"X-API-Key": api_key},
    timeout=10.0,
) as client:
    response = client.get("/v2/snapshot", params={"symbol": "AAPL"})
    body = response.json()

    if "error" in body:
        error = body["error"]
        raise RuntimeError(
            f"{error['code']}: {error['message']} (retryable={error['retryable']})"
        )

    response.raise_for_status()
    data = body["data"]
    # Headline multiples are {value, vs_5y} objects: read the number at .value.
    pe = data["fundamentals_quick"]["pe_ttm"]["value"]
    print(data["symbol"], data["freshness"], data["as_of"], data["quote"]["price"], pe)

Next steps

Most apps call GET /v2/valuation?symbol=AAPL next; it pairs with snapshot and is available on Free keys. It ranks each multiple against the symbol’s own 3/5/10-year history (a percentile plus a label), never against peers or a fair-value target. If your question is not valuation, the endpoint guide maps jobs to routes.

Choose endpoints

Pick the smallest route set for your job.

Errors and retries

Build retry behavior around error.retryable.

Hosted MCP

Connect MCP if you are building agents.