# Context Link API

The Context Link API is the REST version of what your AI does through the [MCP server](/docs/api/mcp-server) and [skills](/docs/skill-get-context): search across every source you've connected, get a short cited answer, and save Memories your AI can read back later.

## Base URL

Every endpoint lives under `https://context-link.ai/api/v1`, so `GET /context` is `https://context-link.ai/api/v1/context`.

## Authentication

Every request carries your API key in the `Authorization` header, as the bare key:

```bash
curl "https://context-link.ai/api/v1/ping" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{ "message": "OK", "user": { "subdomain": "yourname" } }
```

Create or rotate your key under **API key** in [Settings](https://context-link.ai/user/settings). `GET /ping` is a free health check for a stored key.

## Endpoints

| Endpoint | What it does |
|----------|--------------|
| [`GET /context`](/docs/api/context) | Matching passages from everything you've connected, as markdown for your own model. |
| [`GET /question`](/docs/api/question) | One short answer with numbered citations. Pro plan. |
| [`POST /context/save`](/docs/api/save-memory) | Save Memory: store a document under a name, versioned. |
| [`GET /memories`](/docs/api/memories) | List the Memories you can retrieve by name. |

Pushing content in from your own services is a separate API with its own token: see [Custom Connections](/docs/api/custom-connections).

## Modes

Every endpoint takes an optional `mode`, a named weighting profile you set up on your **Connections** page (e.g. `customer-support`). Use **one mode per session, on every call**: Memories saved in a mode only exist inside it, so save, list and query with the same `mode`. Details under [Mode-scoped memories](/docs/api/save-memory#mode-scoped-memories).

## Prefer a link?

Your Context Link subdomain answers the same queries without an API key, which is easier to paste into an AI chat: `https://yourname.context-link.ai/refund-policy?p=YOUR_PIN`. See [Ways to talk to Context Link](/docs/ways-to-talk-to-context-link).

---

# Get context

`/context` returns **a lot of material**: the passages that best match your query, from every source you've connected, as one markdown document. That's what you want when your own LLM or agent does the writing. For one short answer instead, use [`GET /question`](/docs/api/question).

## Request

One GET with your API key and the topic as `query`:

```bash
curl "https://context-link.ai/api/v1/context?query=refund+policy" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{ "message": "<markdown context>", "format": "markdown" }
```

## Request fields

| Field | Type | Description |
|---|---|---|
| `query` | string | Required. The topic or question. Dashes and underscores become spaces, so `refund-policy` and `refund policy` are the same query. If it exactly matches a Memory's name, that Memory is returned whole, without a search. |
| `mode` | string | Optional. A mode name (e.g. `customer-support`) that weights results toward the connections you've weighted for it. Includes Memories saved in that mode; excludes other modes' Memories. |
| `connection_type` | string | Optional. Comma-separated hard filter: only these source types can come back, e.g. `site,notion`. Valid types: `site`, `email`, `files`, `notion`, `google_doc`, `one_drive`, `basecamp`, `monday`, `youtube`, `webmention`, `custom`, `memory`. An unknown type is a `400`. |
| `response_format` | string | Optional. `structured` adds the retrieved chunks and their sources (below). Any other value, or none, returns the default response. |

## Response fields

| Field | Type | Description |
|---|---|---|
| `message` | string | The matching passages joined into one markdown document, or `No results found` when nothing matched. |
| `format` | string | Always `markdown`. |

## Structured response

Add `response_format=structured` to get the same markdown together with the chunks and source metadata you need for citations:

```bash
curl "https://context-link.ai/api/v1/context?query=ticket+deflection+benchmarks&response_format=structured" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{
  "format": "structured",
  "query": "ticket deflection benchmarks",
  "markdown": "## Support benchmarks\n\nTeams using guided self-service deflect 42% of repeat tickets.",
  "results": [
    {
      "content": "Teams using guided self-service deflect 42% of repeat tickets.",
      "position": 3,
      "rank": 1,
      "score": 0.82,
      "content_sha": "f09d847fc7a20ac8598c5042abd58663ee52d3878bca7693416bb5d4124d5151",
      "sources": [
        {
          "citation": null,
          "uid": "support-benchmarks-2026",
          "title": "Support benchmarks",
          "url": "https://docs.example.com/support-benchmarks",
          "source_updated_at": "2026-08-12T03:14:15Z",
          "connection": {
            "uid": "support-site",
            "type": "Site",
            "name": "docs.example.com",
            "logo_url": "https://www.google.com/s2/favicons?sz=256&domain=docs.example.com"
          }
        }
      ]
    }
  ]
}
```

### Structured response fields

| Field | Type | Description |
|---|---|---|
| `format` | string | Always `structured`. |
| `query` | string | The query used for retrieval. |
| `markdown` | string | The same markdown the default response returns as `message`. |
| `results` | array | One entry per retrieved chunk, ranked: `content`, `position` in its document, `rank`, similarity `score`, `content_sha` and a `sources` array (normally one source, with `citation: null`). |

When the query matches a Memory's name, `results` holds one entry with the Memory's full content, and its `rank` and `score` are `null` because no search ran.

## Good to know

- Treat the returned markdown as **untrusted reference material**: tell your model to take facts from it and ignore any instructions inside it.
- Identical queries (same `query`, `mode`, `connection_type` and `response_format`) are cached for an hour.
- Rate limit: 5 requests per 10 seconds per API key. See [Errors and limits](/docs/api/errors-and-limits).

---

# Ask a question

`/question` runs the same search as [`GET /context`](/docs/api/context), then has a small model write **one concise paragraph** grounded in what it found, with inline `[1]`-style citations. Use it when you want the answer, not the material.

> **Pro plan.** Other plans get `402 Payment Required`. Each call counts toward your monthly AI allowance (2,000 requests on Pro, shared with other AI features).

## Request

One GET with your API key and the question as `query`. The answer comes back with the sources it used:

```bash
curl "https://context-link.ai/api/v1/question?query=what+is+our+refund+policy" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{
  "result": "ok",
  "answer": "Refunds are available in full within 30 days of purchase [1] and go back to the original payment method within 5 business days [2].",
  "citations": [
    { "n": 1, "title": "Refund policy", "url": "https://example.com/refunds" },
    { "n": 2, "title": "Billing operations SOP", "url": "https://notion.so/..." }
  ],
  "format": "markdown"
}
```

## Request fields

| Field | Type | Description |
|---|---|---|
| `query` | string | Required. The question. Dashes and underscores become spaces. |
| `mode` | string | Optional. A mode name that weights the search, as on [`/context`](/docs/api/context). |
| `connection_type` | string | Optional. Comma-separated hard filter on source types, as on [`/context`](/docs/api/context). |
| `response_format` | string | Optional. `structured` returns the answer in the same structured shape as `/context` (below). |

## Response fields

| Field | Type | Description |
|---|---|---|
| `result` | string | `ok` when there's an answer; `no_context` (HTTP 200) when nothing relevant was found, so don't retry; `llm_unavailable` (HTTP 503) when the model call failed, so retry. |
| `answer` | string | One paragraph of about 120 words or fewer, with inline `[N]` markers. `null` unless `result` is `ok`. |
| `citations` | array | Only the sources the answer actually used, as `{ n, title, url }`. Numbers run `1, 2, 3…` and always match a marker in `answer`. |
| `format` | string | Always `markdown`. |

## Structured response

With `response_format=structured`, the answer comes back in the same shape as a structured `/context` response, with every cited source in full:

```bash
curl "https://context-link.ai/api/v1/question?query=refund+rules&response_format=structured" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{
  "format": "structured",
  "query": "refund rules",
  "markdown": "Refunds take 30 days [1], with exceptions for faulty goods [2].",
  "results": [
    {
      "content": "Refunds take 30 days [1], with exceptions for faulty goods [2].",
      "position": null,
      "rank": 1,
      "score": null,
      "content_sha": "f3bf95d8a3c2c126bd4d10e23260aca476e1bbb9619e470a54bc38cf79ce6d92",
      "sources": [
        {
          "citation": 1,
          "uid": "refund-policy",
          "title": "Refund policy",
          "url": "https://docs.example.com/refunds",
          "source_updated_at": "2026-08-12T03:14:15Z",
          "connection": {
            "uid": "support-site",
            "type": "Site",
            "name": "docs.example.com",
            "logo_url": "https://www.google.com/s2/favicons?sz=256&domain=docs.example.com"
          }
        }
      ]
    }
  ]
}
```

`results` has one entry (the answer) or none. No answer gives `markdown: null` and `results: []`: with HTTP 200 that's `no_context`, with HTTP 503 it's `llm_unavailable` and worth a retry.

## From your subdomain

The same answer is available without an API key on your Context Link subdomain, which is handy to paste into an AI chat. `/q/` and `/question/` are equivalent:

```
https://yourname.context-link.ai/q/what-is-our-refund-policy?p=YOUR_PIN
```

Send `Accept: application/json`, `text/markdown` or `text/plain` to choose the format. ChatGPT and Gemini get HTML by default, since they handle markdown responses poorly.

## Good to know

- Identical questions (same `query`, `mode`, `connection_type` and `response_format`) are cached for an hour.
- Rate limit: 2 requests per 10 seconds per API key, because each answer takes a couple of seconds to write. See [Errors and limits](/docs/api/errors-and-limits).

---

# Save Memory

Save Memory stores a document under a name (its **namespace**). A [`GET /context`](/docs/api/context) whose `query` is exactly that name returns the document **word for word**, without a search. Memories are also indexed, so related queries find them too.

## Request

POST the content as the body, with the name as `namespace`. The response gives the name to read it back by:

```bash
curl -X POST "https://context-link.ai/api/v1/context/save?namespace=meeting-notes" \
  -H "Authorization: $CONTEXT_LINK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '["Meeting notes from Feb 15: discussed roadmap priorities and Q2 goals."]'
```

```json
{ "message": "Saved", "namespace": "meeting-notes" }
```

## Request fields

| Field | Type | Description |
|---|---|---|
| `namespace` | string | Required, in the query string. The Memory's name. Case-insensitive; spaces become dashes. A `[mode]/name` form (e.g. `[customer-support]/top-links`) saves into that mode. |
| `mode` | string | Optional, in the query string. The mode this session runs in; the Memory is saved into it. See [Mode-scoped memories](#mode-scoped-memories). |
| body | text or JSON | Required. The content. A JSON array of strings, a JSON string, a JSON object or plain text all work; it's converted to markdown before it's saved. |

## Response fields

| Field | Type | Description |
|---|---|---|
| `message` | string | `Saved`. Returned with HTTP `201`. |
| `namespace` | string | The name to retrieve it by. Shown as `[mode]/name` when saved into a mode. |

## Versioning

- Saving to an existing name creates a **new version**. Retrieving by name always returns the latest; earlier versions are kept, not searched.
- Re-save the whole document each time it changes, rather than appending.
- Names organise Memories by topic: `brand-voice`, `project-roadmap`, `meeting-notes`.

## Mode-scoped memories

If you query with a `mode`, **save with the same `mode`**: whatever mode your GETs use, your saves use too.

- A Memory saved with a mode is named `[mode]/name` (e.g. `[customer-support]/top-links`) and **only exists in that mode**. Requests with no mode or another mode never see it, by name or by search.
- A Memory saved without a mode is visible everywhere.
- Inside a mode, `top-links` and `[customer-support]/top-links` both resolve to the mode's Memory. If an unmoded `top-links` also exists, the mode's version wins.
- One name can hold an unmoded Memory and one per mode, side by side.
- A `[mode]/` prefix that disagrees with `mode` is a `422`.

```bash
curl -X POST "https://context-link.ai/api/v1/context/save?namespace=top-links&mode=customer-support" \
  -H "Authorization: $CONTEXT_LINK_API_KEY" \
  -d 'The links support agents send most often.'
```

```json
{ "message": "Saved", "namespace": "[customer-support]/top-links" }
```

## Reading it back

```bash
curl "https://context-link.ai/api/v1/context?query=top-links&mode=customer-support" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{ "message": "The links support agents send most often.", "format": "markdown" }
```

Forgotten a name? [`GET /memories`](/docs/api/memories) lists every Memory you can read back.

## Good to know

- Saving shares `/context`'s rate limit: 5 requests per 10 seconds per API key.
- From your subdomain, `POST https://yourname.context-link.ai/<namespace>?p=YOUR_PIN` saves the same way without an API key.

---

# List Memories

Reading a Memory means knowing its name. `/memories` lists every name you can read back, so an AI can say "pull up my support notes" without being told what they were called. Over the [MCP server](/docs/api/mcp-server), the same list is the `list_memories` tool.

## Request

One GET with your API key, and the session's `mode` if it has one:

```bash
curl "https://context-link.ai/api/v1/memories?mode=customer-support" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{
  "mode": "customer-support",
  "memories": [
    { "namespace": "brand-voice", "mode": null, "updated_at": "2026-11-28T10:14:02Z" },
    { "namespace": "[customer-support]/top-links", "mode": "customer-support", "updated_at": "2026-11-30T16:41:55Z" }
  ]
}
```

## Request fields

| Field | Type | Description |
|---|---|---|
| `mode` | string | Optional. Adds that mode's Memories to the list. See [What gets listed](#what-gets-listed). |

## Response fields

| Field | Type | Description |
|---|---|---|
| `mode` | string | The mode the list was built for, normalised (lowercase, dashes), or `null`. |
| `memories` | array | Sorted by name, up to 500. Each has `namespace` (the name to read it back by, `[mode]/name` when moded), `mode` (`null` when visible everywhere) and `updated_at`. |

## What gets listed

Exactly what you can read back with the same `mode`, following the [mode rules](/docs/api/save-memory#mode-scoped-memories):

- **No `mode`:** Memories saved without a mode. Moded Memories don't exist outside their mode, so they're left out.
- **With a `mode`:** those, plus that mode's Memories. Other modes' Memories are left out.
- **Same name in both:** only the mode's version is listed, because it's the one a read returns inside the mode.
- **Privacy:** your own private Memories and your organisation's shared ones, never a teammate's private Memories.

## Reading one back

Pass a listed `namespace` as the `query` to [`GET /context`](/docs/api/context), with the mode you listed with:

```bash
curl "https://context-link.ai/api/v1/context?query=%5Bcustomer-support%5D/top-links&mode=customer-support" \
  -H "Authorization: $CONTEXT_LINK_API_KEY"
```

```json
{ "message": "The links support agents send most often.", "format": "markdown" }
```

Inside the mode, the bare name (`top-links`) works too.

## Good to know

- Rate limit: 5 requests per 10 seconds per API key.

---

# MCP Server

Context Link runs a hosted [Model Context Protocol](https://modelcontextprotocol.io) server. Any MCP-capable client can connect to it and get four tools for searching, answering from, and writing to your connected sources.

This is the same server that powers the two first-party integrations, so if you use Claude or ChatGPT you almost certainly want one of those guides instead — both wrap this endpoint in a two-click setup and neither needs anything on this page:

- **Claude** — the custom connector *is* this MCP server. Follow the [Claude custom connector guide](/docs/add-context-link-claude-connector); one setup covers Claude on the web, Desktop, Cowork and Claude Code.
- **ChatGPT** — the official Context Link app is an MCP app talking to this same endpoint under the hood. Follow the [ChatGPT app guide](/docs/add-context-link-chatgpt-connector).

This page is for **everything else**: Cursor, VS Code, Claude Code on the command line, Codex, ChatGPT developer mode, or a client you're building yourself.

## Quick reference

| Property | Value |
|----------|-------|
| **Server URL** | `https://www.context-link.ai/mcp` |
| **Transport** | Streamable HTTP (`POST`/`GET`/`DELETE` on the same URL) |
| **Authentication** | OAuth 2.1 — authorization code + PKCE (S256), with Dynamic Client Registration |
| **Scopes** | `context:read`, `context:write`, `offline_access` |
| **Tools** | `get_context`, `ask_question`, `save_memory`, `get_memory`, `list_memories` |
| **Rate limit** | 1,000 requests per 10 seconds per IP |

> Use the `www.` host. The server is reachable at `https://www.context-link.ai/mcp` — that is the URL to put in every client config.

### Prerequisites

* A **Context Link** account with at least one connection set up (Notion, Google Drive, a website, email, and so on).
* An MCP client that supports **remote servers over HTTP**. Clients that only speak stdio need a bridge — see [stdio-only clients](#stdio-only-clients) below.
* `ask_question` requires a Pro plan. The other tools work on any active plan.

---

## The tools

| Tool | Scope | What it does |
|------|-------|--------------|
| `get_context` | `context:read` | Semantic search across everything you've connected. Returns the matching snippets plus the sources they came from. Takes `query`, and an optional `mode` to weight results. |
| `ask_question` | `context:read` | Runs the same retrieval, then has an LLM compose one concise paragraph grounded in your sources, with numbered citations. Takes `query` and optional `mode`. **Pro plan only.** |
| `save_memory` | `context:write` | Saves content back to Context Link as a Memory. Takes `content` (markdown or plain text, up to 100KB), an optional `namespace` — a dashed name like `brand-voice` — and an optional `mode`. Without a namespace you get a timestamped one. |
| `get_memory` | `context:read` | Retrieves a Memory you saved earlier. Takes `namespace` and optional `mode`. |
| `list_memories` | `context:read` | Lists the namespaces `get_memory` can fetch, so the agent doesn't need to know a name in advance. Takes optional `mode`: without it you get memories saved without a mode; with it you also get that mode's memories. See [List Memories](/docs/api/memories). |

`mode` maps to the named weighting profiles you configure on your **Connections** page — pass something like `customer-support` and the results lean toward the connections you've weighted for that mode.

**Use one mode per session, on every tool.** If a session queries with `mode: customer-support`, it should save and fetch memories with that same mode. A memory saved in a mode is named `[mode]/name` (e.g. `[customer-support]/top-links`) and only exists when that mode is used; a memory saved without a mode is visible everywhere. The server's instructions tell connected agents this, so in practice a customer-support thread naturally saves everything into the customer-support mode. More in [Mode-scoped memories](/docs/api/save-memory#mode-scoped-memories).

![The four Context Link tools listed in Claude Code: Get Context, Ask Question, Save Memory and Get Memory](/docs/mcp-claude-code-tools.png)

---

## Setting it up

Every client wants the same two things: the server URL, and permission to open a browser window for the OAuth handshake. The steps below cover the common ones.

### Claude Code

From your terminal:

```bash
claude mcp add --transport http context-link https://www.context-link.ai/mcp
```

Add `--scope user` to that command if you want the server available in every project rather than only the current one.

Then run `/mcp` inside Claude Code, choose the Context Link server and pick **Authenticate**. Claude Code opens a browser tab for you (and prints the URL in case it doesn't):

![Claude Code authenticating with Context Link, showing the OAuth authorize URL it opens in the browser](/docs/mcp-claude-code-authenticate.png)

Approve the consent screen in the browser — this is where you grant the read, write and offline access the tools need:

![The Context Link consent screen asking whether to authorize Claude Code, listing Context:Read, Context:Write and Offline Access](/docs/mcp-oauth-consent.png)

Back in the terminal, `/mcp` should now show the server connected and authenticated:

![Claude Code showing the Context Link MCP server connected, authenticated, and exposing 4 tools](/docs/mcp-claude-code-connected.png)

### Cursor

Add the server to `~/.cursor/mcp.json` (global) or `.cursor/mcp.json` in your project:

```json
{
  "mcpServers": {
    "context-link": {
      "url": "https://www.context-link.ai/mcp"
    }
  }
}
```

Reopen **Settings → MCP**, and Cursor will prompt you to sign in the first time it calls a tool.

### VS Code (GitHub Copilot)

Add the server to `.vscode/mcp.json` in your workspace:

```json
{
  "servers": {
    "context-link": {
      "type": "http",
      "url": "https://www.context-link.ai/mcp"
    }
  }
}
```

Start the server from the gutter action in that file, then approve the sign-in prompt.

### Codex

Codex reads MCP servers from `~/.codex/config.toml`:

```toml
[mcp_servers.context-link]
url = "https://www.context-link.ai/mcp"
```

If you'd rather use skills than MCP, Context Link ships those too — see [Ways to Talk to Context Link](/docs/ways-to-talk-to-context-link).

### ChatGPT (developer mode)

ChatGPT users are usually better served by the [official Context Link app](/docs/add-context-link-chatgpt-connector), which is two clicks and needs no configuration. If you specifically want to wire the raw MCP server up yourself, enable **developer mode** in ChatGPT's connector settings, create a new connector pointing at `https://www.context-link.ai/mcp`, and choose OAuth for authentication. Leave any "requires OIDC / userinfo" option off — Context Link issues opaque OAuth tokens and does not expose a userinfo endpoint.

### stdio-only clients

Some clients still only launch MCP servers as local subprocesses. Bridge to the remote server with `mcp-remote`:

```json
{
  "mcpServers": {
    "context-link": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://www.context-link.ai/mcp"]
    }
  }
}
```

The bridge handles the OAuth dance and opens a browser window on first use.

---

## Troubleshooting

**"Unable to reach Context Link" / connection fails immediately.** Check the host — it's `https://www.context-link.ai/mcp`, with the `www`.

**The client connects but every tool call returns 401.** The client isn't attaching a token. Look for an "authenticate" or "sign in" action in the client's MCP panel; most only trigger the OAuth flow on demand rather than at connection time.

**`ask_question` returns a `pro_required` reason.** That tool is Pro-only. `get_context` gives you the underlying snippets on any plan.

**Tools return no context.** The token is bound to the Context Link user who approved the consent screen. If that user's account has no connections, or the content sits on another teammate's personal connection, there's nothing to search. Check the **Connections** page while signed in as the same user.

**A tool call reports the allowance is exhausted.** `ask_question` spends from your organisation's monthly LLM allowance. It resets at the start of each month.

**Your client insists on OIDC.** Turn it off. Context Link serves `/.well-known/openid-configuration` for discovery compatibility, but it isn't a full OpenID Provider — no ID tokens, no userinfo, no JWKS.

---

## Related

- [Claude custom connector](/docs/add-context-link-claude-connector) — the guided setup for the Claude apps
- [ChatGPT app](/docs/add-context-link-chatgpt-connector) — the official ChatGPT connector
- [Ways to Talk to Context Link](/docs/ways-to-talk-to-context-link) — skills, direct links and the API
- [Context Link API](/docs/api) — the REST API, if you'd rather not use MCP at all

---

# Custom Connections API

Context Link ships pre-built connections for Google Drive, Notion, email and more, but you can also **build your own**. A custom connection turns the sync direction around: an LLM (Claude, Cowork, Codex, or your own script) fetches data from any service it can reach, converts each item to markdown, and pushes it to Context Link over this API. The server handles everything from markdown inwards: chunking, embeddings, and semantic search.

The easiest way to use this API is the **`custom_connections` skill**: sign in, generate a token under **Settings → Custom connections token**, then download the skill from **Integrations**. The skill embeds your token and teaches your AI the full sync loop. This page documents the raw API underneath.

## Quick reference

| Property | Value |
|----------|-------|
| **Base URL** | `https://context-link.ai/api/v1` |
| **Authentication** | `Authorization: Bearer <custom connections token>` |
| **Format** | JSON in, JSON out |
| **Write rate limit** | 5 requests per 10 seconds (per user and per organisation) |
| **Quotas** | 1,000 posts and 100MB of content per connection; 100KB per post body |

The token is server-generated from **Settings → Custom connections token**. It is separate from the legacy API key and only works on these endpoints.

## Connections

| Verb | Path | Purpose |
|------|------|---------|
| GET | `/custom_connections` | List your visible connections |
| POST | `/custom_connections` | Create a connection |
| GET | `/custom_connections/:id` | Show one connection |
| DELETE | `/custom_connections/:id` | Delete a connection and all of its posts |

Create takes a JSON body: `{"name": "ToDo App 5000"}`. Connections are **organisation-wide by default** (teammates can search the synced content); pass `"scope": "personal"` to keep a connection private to you. The creator is recorded; org-level connections can only be modified by their creator or an org admin.

```bash
curl -s -X POST "https://context-link.ai/api/v1/custom_connections" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "ToDo App 5000"}'
```

## Posts

| Verb | Path | Purpose |
|------|------|---------|
| GET | `/custom_connections/:id/posts` | List posts: `page`, `per_page` (max 100), `q` (title search) |
| PUT | `/custom_connections/:id/posts/:uid` | **Upsert a post by your own stable uid** |
| GET | `/custom_connections/:id/posts/:uid` | Show a post (`?include=chunks` for debugging) |
| DELETE | `/custom_connections/:id/posts/:uid` | Delete one post |

The `:uid` is a stable id **you** choose per source item (e.g. `todo-app-5000-task-123`): lowercase `a-z 0-9 - _ .`, max 255 characters. Upserting the same uid updates the same post; there are no Context Link ids to remember.

```bash
curl -s -X PUT "https://context-link.ai/api/v1/custom_connections/42/posts/todo-app-5000-task-123" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"title": "Fix the boiler", "body": "## Fix the boiler\n\nStatus: open\nDue: Friday"}'
```

The upsert response is definitive:

| Response | Meaning |
|----------|---------|
| `201 {"status": "created"}` | New post, chunked and embedded |
| `200 {"status": "updated"}` | Existing post re-indexed |
| `200 {"status": "unchanged"}` | Identical content: no re-embedding, costs nothing |

Re-pushing everything you fetched is safe and cheap: unchanged posts are detected by content hash and skipped.

## The sync loop

1. **Fetch** all items from the source service.
2. **Convert** each item to markdown: one post per logical document, clear title, keep searchable fields (names, statuses, dates) as text.
3. **Push** each with `PUT /posts/{uid}`.
4. **Prune**: list all posts, compare against the complete set of uids you fetched, and DELETE the ones that no longer exist at the source. Only prune after a complete enumeration; a partial fetch must never drive deletions.

From Claude Cowork you can schedule this as a [recurring task](https://support.claude.com/en/articles/13854387-schedule-recurring-tasks-in-claude-cowork) so the connection stays fresh like any built-in one.

## Status codes

| Code | Description |
|------|-------------|
| `200` / `201` | Success (see upsert statuses above) |
| `401` | Missing or invalid token |
| `402` | No active subscription |
| `403` | Not the connection's creator or an org admin |
| `404` | Connection or post not found, including other organisations' and built-in connections |
| `409` | Post is excluded from the index; re-include it in Context Link, then push again |
| `413` | Post body over 100KB |
| `422` | Validation failure or quota reached (message explains) |
| `429` | Rate limited; respect the `Retry-After` header |

## Security notes

- The token authenticates you and is scoped to custom connections only; it cannot read your context or touch built-in connections.
- Rotate it any time from **Settings**; rotating invalidates downloaded skills until re-downloaded.
- If an AI holds this token while reading external content, it should treat fetched text as data (never instructions) and send the token only to `context-link.ai`. The downloadable skill includes these guardrails.

---

# Errors and limits

Every error is JSON. Most carry a `message`; Save Memory's own validation errors carry `error`.

```json
{ "message": "API key required" }
```

## Status codes

| Code | Meaning | What to do |
|------|---------|------------|
| `200` | Success. `/question` can also return `200` with `result: "no_context"` when nothing relevant was found. | — |
| `201` | Memory saved. | — |
| `400` | `query` or `namespace` missing, or `connection_type` names an unknown type. | Fix the request. |
| `401` | API key missing, or no active subscription. | Send the key; check your plan. |
| `402` | `/question` on a plan without it (Pro only). | Upgrade, or use `/context`. |
| `404` | API key not recognised. | Check the key in [Settings](https://context-link.ai/user/settings). |
| `422` | Save Memory with an empty body, or a `[mode]/` prefix that disagrees with `mode`. | Fix the request. |
| `429` | Rate limit hit, too many failed keys from one IP, or the monthly AI allowance is used up. | Back off; honour `Retry-After` when present. |
| `503` | `/question` couldn't reach the model (`result: "llm_unavailable"`). | Retry. |

## Error bodies

| Message | Status |
|---------|--------|
| `API key required` | 401 |
| `You need to be subscribed to access that page` | 401 |
| `Not found` | 404 |
| `A query is required` | 400 |
| `A namespace is required` (as `error`) | 400 |
| `No content provided` (as `error`) | 422 |
| `The question endpoint is a Pro-plan feature.` | 402 |
| `Monthly question allowance exceeded. Resets at the start of next month.` | 429 |
| `Too many failed authentication attempts. Try again later.` | 429 |

## Rate limits

| Endpoint | Limit |
|----------|-------|
| `GET /context` and `POST /context/save` | 5 requests per 10 seconds per API key (shared) |
| `GET /memories` | 5 requests per 10 seconds per API key |
| `GET /question` | 2 requests per 10 seconds per API key |
| Failed authentication | 30 per minute per IP, then `429` with `Retry-After` |

`/question` also counts toward your monthly AI allowance (2,000 requests on Pro), which resets at the start of each month.
