> **For coding agents and LLMs:** This is one page from the Social Fetch docs (markdown export). For curated orientation and workflow guidance, start with [`/llms.txt`](https://www.socialfetch.dev/llms.txt); for agent onboarding and crawl rules, use [`/agents.txt`](https://www.socialfetch.dev/agents.txt); for the full endpoint list with links to pages like this one, use [`/llms-endpoints.txt`](https://www.socialfetch.dev/llms-endpoints.txt); for one platform's parameters and curls, use [`/llms-{platform}.txt`](https://www.socialfetch.dev/llms-tiktok.txt); use [`/llms.json`](https://www.socialfetch.dev/llms.json) when you need structured JSON for tool registration.

## This page

- **On-site (HTML):** <https://www.socialfetch.dev/docs/authentication>
- **Markdown (.mdx) URL:** <https://www.socialfetch.dev/docs/authentication.mdx>

## API base URL and authentication

- **API origin (from OpenAPI `servers`):** `https://api.socialfetch.dev`
- **Authentication:** send `x-api-key: sfk_...` on `/v1/**` and `/v2/**` routes unless the operation is explicitly anonymous (check OpenAPI `security`, the [API reference hub](https://www.socialfetch.dev/docs/api.mdx), [`/llms.txt`](https://www.socialfetch.dev/llms.txt), or [`/llms.json`](https://www.socialfetch.dev/llms.json) for each route).
- **OpenAPI JSON:** <https://www.socialfetch.dev/openapi.json>

## Recommended docs entrypoints (this site)

- [Documentation overview](https://www.socialfetch.dev/docs.mdx) — top-level orientation (markdown).
- [Quickstart](https://www.socialfetch.dev/docs/quickstart.mdx) — authenticate with `x-api-key`, validate auth with `whoami`, and understand the JSON envelope.
- [SDK](https://www.socialfetch.dev/docs/sdk.mdx) — official TypeScript SDK guide, including `SocialFetchClient`, `Result`, and `unwrap()`.
- [Capability matrix](https://www.socialfetch.dev/docs/capability-matrix.mdx) — every operation with identifiers, pagination, outcomes, media download, credits, and its SDK method. Generated from OpenAPI, so use it for route selection instead of scanning individual pages.
- [Recipes](https://www.socialfetch.dev/docs/recipes.mdx) — copyable workflows (brand monitoring, transcripts, Ad Library, creator scoring, Reddit research) with credit callouts and SDK examples.
- [Integrations](https://www.socialfetch.dev/docs/integrations.mdx) — MCP for AI clients, n8n verified node, Apify Store Actors, Make custom app, SDK, and REST API connection paths.
- [MCP product page](https://www.socialfetch.dev/mcp) — hosted MCP overview, OAuth, Skills install.
- [MCP integration](https://www.socialfetch.dev/docs/integrations/mcp.mdx) — hosted `/mcp` server, OAuth, Cursor/VS Code/Claude install snippets, 1112 endpoint tools, plus docs_search/docs_read for implementation help.
- [n8n integration](https://www.socialfetch.dev/docs/integrations/n8n.mdx) — install `n8n-nodes-socialfetch`, credentials, and workflow examples.
- [Apify integration](https://www.socialfetch.dev/docs/integrations/apify.mdx) — Store Actors under @social-fetch, PPE billing, dataset export, and quick start.
- [Make integration](https://www.socialfetch.dev/docs/integrations/make.mdx) — custom app modules for Make scenarios, API key credentials, and module catalog.
- [`/llms-endpoints.txt`](https://www.socialfetch.dev/llms-endpoints.txt) — every documented operation with a direct link to that route's agent-readable markdown page (prefer this over parsing OpenAPI).
- [`/llms-{platform}.txt`](https://www.socialfetch.dev/llms-tiktok.txt) — per-platform endpoint files generated from OpenAPI (parameters, credits, curls).
- [`/agents.txt`](https://www.socialfetch.dev/agents.txt) — agent crawl/onboarding file with capabilities, auth rules, and allowlist.
- [`/llms.json`](https://www.socialfetch.dev/llms.json) — structured machine-readable operation inventory with parameter names, pagination, outcomes, credits, and SDK mapping.
- [API reference hub](https://www.socialfetch.dev/docs/api.mdx) — human-friendly index of operations with links into generated pages.
- [Errors](https://www.socialfetch.dev/docs/errors.mdx) — shared error envelope and HTTP status guidance.
- [Credits](https://www.socialfetch.dev/docs/credits.mdx) — metering, `402`, and planning batch jobs.
- [Authentication](https://www.socialfetch.dev/docs/authentication.mdx) — `x-api-key` header, the `SOCIALFETCH_API_KEY` environment variable, and a curl check.
- [Rate limits](https://www.socialfetch.dev/docs/rate-limits.mdx) — no per-minute cap on paid lookups with a key, 200 in flight per workspace, per-minute limits on free and keyless routes, `429`/`503` and `Retry-After`.
- [CLI and agents](https://www.socialfetch.dev/docs/cli-and-agents.mdx) — curl and jq, the `socialfetch` CLI, MCP and the agent skill from a terminal.
- [`/pricing.json`](https://www.socialfetch.dev/pricing.json) — machine-readable pricing: credit packs, plans, free credits and each endpoint's credit cost.
- Outcome semantics such as `found`, `not_found`, and `private` are documented in [Errors](https://www.socialfetch.dev/docs/errors.mdx) and on operation pages when present in the OpenAPI contract.

## Markdown docs convention

- Every docs page has a markdown twin: append **`.mdx`** to the docs pathname (for example `/docs/quickstart` → `/docs/quickstart.mdx`).
- Agents that send `Accept: text/markdown` on `/docs/**` HTML URLs may receive markdown directly (same URL, `Vary: Accept`).
- Published blog posts use the same convention: `/blog/{slug}` → `/blog/{slug}.mdx`, or `Accept: text/markdown` on the HTML URL (`Vary: Accept`).

---
# Authentication (https://www.socialfetch.dev/docs/authentication)

Every request to `https://api.socialfetch.dev` authenticates with an API key sent in the `x-api-key` header. Keys start with `sfk_`. There's no OAuth flow or token exchange for the REST API: the key is the whole credential, so it works the same from a terminal, a server, a CI job or an AI agent.

## 1. Create a key

Sign up at [app.socialfetch.dev/signup](https://app.socialfetch.dev/signup) (new accounts get free credits, no card needed), then create a key under [API Keys](https://app.socialfetch.dev/api-keys). The full key is shown once, so copy it then. [Quickstart](/docs/quickstart#2-create-an-api-key) walks through it with screenshots.

## 2. Put it in `SOCIALFETCH_API_KEY`

Every example in these docs, the [TypeScript SDK](/docs/sdk) and the `socialfetch` CLI read the key from the `SOCIALFETCH_API_KEY` environment variable:

```bash
export SOCIALFETCH_API_KEY=sfk_...
```

For a `.env` file or PowerShell:

```bash
export SOCIALFETCH_API_KEY="sfk_..."
```

In a `.env` file:

```bash
SOCIALFETCH_API_KEY=sfk_...
```

In PowerShell:

```powershell
$env:SOCIALFETCH_API_KEY = "sfk_..."
```

## 3. Test it with curl

`GET /v1/whoami` is free. It returns the account and workspace the key belongs to:

```bash
curl -sS \
  -H "x-api-key: $SOCIALFETCH_API_KEY" \
  "https://api.socialfetch.dev/v1/whoami"
```

Then make a paid lookup the same way. This TikTok profile lookup costs 1 credit:

```bash
curl -sS \
  -H "x-api-key: $SOCIALFETCH_API_KEY" \
  "https://api.socialfetch.dev/v1/tiktok/profiles/charlidamelio"
```

## When authentication fails

| Status | Code                   | Meaning                                                                                                                      |
| ------ | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `401`  | `unauthorized`         | The key is wrong, revoked or expired. On free routes such as `/v1/whoami`, a missing key also returns `401`.                 |
| `402`  | `payment_required`     | No key was sent to a paid route. Check the header name and that `SOCIALFETCH_API_KEY` is set where the command runs.         |
| `402`  | `insufficient_credits` | The key works, but the workspace is out of credits or the key reached its monthly spend limit. See [Credits](/docs/credits). |
| `403`  | `forbidden`            | The key is valid but can't be used right now. `reason` says why.                                                             |

All error bodies share one `{ error }` shape with a `requestId`. See [Errors](/docs/errors).

## Keep the key secret

* Send it only in the `x-api-key` header. Never put it in a URL or query string, where it ends up in logs, and never in `Authorization: Bearer`, which is rejected.
* Keep it on a server or in your own scripts. Never ship it in website front-end code or a mobile app.
* Use one key per app or machine, so you can revoke one without breaking the rest. Owners can set a monthly spend limit on each key ([Teams](/docs/teams#api-keys-and-spending)).

## SDK, CLI and MCP

* **TypeScript SDK**: `new SocialFetchClient({ apiKey: process.env.SOCIALFETCH_API_KEY! })`. See [TypeScript SDK](/docs/sdk).
* **CLI**: `npx socialfetch listen --forward-to <url>` reads `SOCIALFETCH_API_KEY` (or `--api-key`). See [CLI and agents](/docs/cli-and-agents).
* **MCP** (`https://api.socialfetch.dev/mcp`): clients sign in with OAuth in the browser. A client that can't do OAuth can send the same `x-api-key` header. See [MCP](/docs/integrations/mcp).

Limits on how fast you can call the API are in [Rate limits](/docs/rate-limits).