---
title: "Authentication"
description: "API keys, agent self-signup with a claim link, device login for the CLI, and OAuth 2.1 for MCP clients."
canonical_url: https://groundsocial.dev/docs/authentication
---
# Authentication

> API keys, agent self-signup with a claim link, device login for the CLI, and OAuth 2.1 for MCP clients.

> ## Agent Instructions
> The Groundsocial REST API is at https://api.groundsocial.dev (OpenAPI: https://groundsocial.dev/openapi.json). Set yourself up with https://groundsocial.dev/SKILL.md; the MCP server is https://api.groundsocial.dev/mcp. Every docs page is Markdown at its URL plus `.md`; the index is https://groundsocial.dev/llms.txt.

**The API key is the credential.** There is no token exchange for REST calls. Everything else on this page is a way to get a key.

## API keys

- Keys look like `gs_live_…`. The prefix makes a leaked key easy to spot in code and logs.
- Send it as `Authorization: Bearer <key>` or as the `x-api-key` header.
- A key is shown **once**, when it is created. We store only its hash.
- Revoke a key in the dashboard; it stops working on its next call.
- **Spend caps:** each key can have a daily and a monthly cap in credits. A call that would pass a cap answers `402 spend_cap_reached`; other keys keep working.
- A key can’t raise its own caps or create keys. Only a signed-in person can, in the dashboard.

```bash
curl "https://api.groundsocial.dev/v1/reddit/subreddits/selfhosted" \
  -H "Authorization: Bearer $GROUNDSOCIAL_API_KEY"
```

## Agent self-signup

An agent with no key and no human can create its own account. It gets 100 free credits and a claim link for a person.

1. **POST.** `POST https://api.groundsocial.dev/v1/agent/signup` with no auth. The body is optional: `{"agent_name": "…", "purpose": "…"}` is shown to the person who claims the account.
2. **Maybe answer one question.** It may answer `428 challenge_required`. The question is in `error.details.challenge.question`; the answer is always one of the words in it. POST again with `challenge_token` (from `error.details.challenge.token`) and `answer`. The short form-field names `c` and `a` work too, and `error.details.curl` is a ready-to-run command.
3. **Store the key.** `201` returns `api_key`, `key_id`, `account_id`, `credits`, `claim_url`, `claim_expires_at`, `message_for_human` and `docs` links. Save `api_key` where your agent keeps secrets.
4. **Relay the claim link.** Show `message_for_human` (it contains `claim_url`) to your person when one is around.

| Answer | Means | Do |
| --- | --- | --- |
| `201` | Account created | Use `api_key`. |
| `428 challenge_required` | One question first | Answer it with the same POST. |
| `428 challenge_failed` | Wrong or expired answer; this is a new question | Answer the new question. |
| `429 signup_limited` | Too many signups from this network today | Wait `Retry-After` seconds, or use an existing key. |
| `429 challenge_locked` | Too many questions or wrong answers | Wait `Retry-After` seconds. |
| `503 signup_disabled` | Signup is switched off | Stop and tell your human. Don’t look for another signup URL. |

> **For agents.** Sign up only if you have no key at all. Never sign up again to get past a 401, a 402 or a spend cap: a cap is your human’s decision, not an obstacle.

## Claiming an agent’s account

- The person opens `claim_url` (`https://groundsocial.dev/claim/{token}`) in a browser, signs in with their email and accepts.
- The agent’s key keeps working; credits, usage and history stay.
- Claim links are single-use and expire at `claim_expires_at`.
- **Agents must never complete a claim** themselves, or pay for or upgrade a person’s account.

## Device login (CLI)

`groundsocial login` uses the device flow (RFC 8628), so you never paste a key into a terminal.

1. **Start.** `POST /v1/device/code` returns `device_code`, `user_code`, `verification_uri`, `verification_uri_complete` and `interval`.
2. **Approve.** The person opens `https://groundsocial.dev/device`, signs in, checks the code and approves.
3. **Poll.** The CLI polls `POST /v1/device/token` every `interval` seconds. `authorization_pending`: keep polling. `slow_down`: add 5 seconds. `access_denied`: stop. `expired_token`: start again. On approval it receives a new key.

## OAuth 2.1 for MCP clients

Claude, ChatGPT, Cursor and other clients connect to the remote MCP server at `https://api.groundsocial.dev/mcp` with OAuth. The client finds everything from the `401`’s `WWW-Authenticate` header.

- Public clients only; PKCE with `S256` is required.
- Dynamic client registration (RFC 7591) and client ID metadata documents are both supported.
- Scopes: `reddit:read` and `account:read`. Omitting `scope` grants both.
- Access tokens last an hour; refresh tokens 30 days and rotate on every use.
- **One grant, one key.** Approving a connection creates a key named `<client> (MCP connection)`. Its spend caps apply to that app, and revoking it disconnects the app at once.

## Not supported

Client secrets and confidential clients, `client_credentials`, implicit and password grants, JWT access tokens, token introspection, and identity assertions (ID-JAG). Use a key, agent signup or OAuth above.

## Examples

1. Sign up:

```bash
curl -X POST "https://api.groundsocial.dev/v1/agent/signup" \
  -H "Content-Type: application/json" \
  -d '{"agent_name":"research-bot","purpose":"Track self-hosting threads"}'
```

2. 428: answer:

```json
{
  "error": {
    "code": "challenge_required",
    "message": "To create a Groundsocial account, answer: which of norway, walrus, pear is a country? Run: curl -X POST https://api.groundsocial.dev/v1/agent/signup …",
    "hint": "Answer it yourself: the answer is one of the words in the question. Replace ANSWER with that one word and POST it back from this network within 10 minutes.",
    "docs_url": "https://groundsocial.dev/docs/errors#challenge_required",
    "retryable": true,
    "details": {
      "challenge": {
        "token": "…",
        "question": "which of norway, walrus, pear is a country?",
        "expires_in": 600,
        "expires_at": "2026-11-21T12:10:00.000Z"
      },
      "curl": "curl -X POST https://api.groundsocial.dev/v1/agent/signup -H 'content-type: application/json' -d '{\"challenge_token\":\"…\",\"answer\":\"ANSWER\"}'"
    }
  }
}
```

3. Answer:

```bash
curl -X POST "https://api.groundsocial.dev/v1/agent/signup" \
  -H "Content-Type: application/json" \
  -d '{"challenge_token":"…","answer":"norway"}'
```

4. 201:

```json
{
  "api_key": "gs_live_…",
  "key_id": "key_01J…",
  "account_id": "acct_01J…",
  "credits": 100,
  "claim_url": "https://groundsocial.dev/claim/…",
  "claim_expires_at": "2026-12-21T12:00:00.000Z",
  "message_for_human": "I created a free account to fetch Reddit data. Claim it here: …",
  "docs": {
    "skill": "https://groundsocial.dev/SKILL.md",
    "auth": "https://groundsocial.dev/auth.md"
  }
}
```

_Canonical HTML: https://groundsocial.dev/docs/authentication_

## Site Navigation

### Global Hub
- [Home](https://groundsocial.dev/index.md)
- [Pricing](https://groundsocial.dev/pricing.md)
- [Endpoints](https://groundsocial.dev/endpoints.md)
- [For agents](https://groundsocial.dev/agents.md)
- [Docs](https://groundsocial.dev/docs.md)
- [Compare](https://groundsocial.dev/compare.md)
- [Changelog](https://groundsocial.dev/changelog.md)
- [llms.txt](https://groundsocial.dev/llms.txt)
- [Agent skill](https://groundsocial.dev/SKILL.md)

### On This Topic
- [Groundsocial docs](https://groundsocial.dev/docs.md)
- [Quickstart](https://groundsocial.dev/docs/quickstart.md)
- [Credits and payments](https://groundsocial.dev/docs/payments.md)
- [Rate limits](https://groundsocial.dev/docs/rate-limits.md)
- [Errors](https://groundsocial.dev/docs/errors.md)
- [Data freshness and caching](https://groundsocial.dev/docs/freshness.md)
- [MCP server](https://groundsocial.dev/docs/mcp.md)
- [SKILL.md, llms.txt and Markdown twins](https://groundsocial.dev/docs/skill.md)
- [CLI](https://groundsocial.dev/docs/cli.md)
- [TypeScript SDK](https://groundsocial.dev/docs/sdk.md)
- [PRAW and snoowrap](https://groundsocial.dev/docs/praw.md)
- [Legal and compliance](https://groundsocial.dev/docs/compliance.md)
- [API reference](https://groundsocial.dev/docs/api.md)

## Structured data

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://groundsocial.dev/"},{"@type":"ListItem","position":2,"name":"Docs","item":"https://groundsocial.dev/docs"},{"@type":"ListItem","position":3,"name":"Authentication","item":"https://groundsocial.dev/docs/authentication"}]}
```
