# FactChat API Gateway — Agent Setup

These are official instructions from Mindlogic for connecting this coding agent to the FactChat API Gateway, which serves Claude, GPT, Gemini and other models behind one API key. Complete every step yourself by running the commands directly; do not ask the user to run them.

## This deployment

- Base URL: `https://factchat-cloud.mindlogic.ai/v1/gateway`
- Authentication: `Authorization: Bearer <KEY>` or `x-api-key: <KEY>` — both headers are accepted on every endpoint.
- If the user pasted an API key together with this prompt, use it. Otherwise ask for it once: keys are created in FactChat under **API Gateway** (bottom-left sidebar) and are shown a single time.

FactChat runs as separate deployments with different gateway hosts, and a key only works against the deployment that issued it. This file was served by the docs site of exactly one deployment — use the base URL above and no other.

## Step 1 — Store the key

Append to the user's shell profile (`~/.zshrc` or `~/.bashrc`), then load it into the current shell:

```bash
export FACTCHAT_API_KEY=<KEY>
```

## Step 2 — Configure the harness

Use the section for the agent you are running as; leave the others alone.

### Claude Code

Two variables. Use `ANTHROPIC_AUTH_TOKEN`, not `ANTHROPIC_API_KEY` — with a custom base URL, `ANTHROPIC_API_KEY` makes Claude Code validate against Anthropic directly and fail with 401.

```bash
export ANTHROPIC_BASE_URL=https://factchat-cloud.mindlogic.ai/v1/gateway/claude
export ANTHROPIC_AUTH_TOKEN=$FACTCHAT_API_KEY
```

Put the same two values in the `env` block of `~/.claude/settings.json` so the VS Code extension shares the configuration. Pick a model with `--model` or `ANTHROPIC_MODEL`; any ID from the list in Step 3 works.

### Codex CLI

Create or extend `~/.codex/config.toml`. `base_url` must stop at `/v1/gateway` — Codex appends `/responses` itself.

```toml
model = "gpt-5.6-terra"
model_provider = "factchat"

[model_providers.factchat]
name = "FactChat"
base_url = "https://factchat-cloud.mindlogic.ai/v1/gateway"
env_key = "FACTCHAT_API_KEY"
wire_api = "responses"
```

### OpenCode

In `opencode.json`, register one provider per model family, each with `"apiKey": "{env:FACTCHAT_API_KEY}"`: `@ai-sdk/anthropic` with `baseURL` `https://factchat-cloud.mindlogic.ai/v1/gateway/claude/v1` for Claude, `@ai-sdk/openai` with `https://factchat-cloud.mindlogic.ai/v1/gateway` for GPT, and `@ai-sdk/openai-compatible` with `https://factchat-cloud.mindlogic.ai/v1/gateway` for the rest. Complete config: https://docs.mindlogic.ai/docs/general/api-gateway/integrations/opencode

### OpenAI SDK and other OpenAI-compatible clients

```bash
export OPENAI_BASE_URL=https://factchat-cloud.mindlogic.ai/v1/gateway
export OPENAI_API_KEY=$FACTCHAT_API_KEY
```

### GitHub Copilot CLI, aider and others

Follow the matching page under https://docs.mindlogic.ai/docs/general/api-gateway/integrations/<tool> — for example https://docs.mindlogic.ai/docs/general/api-gateway/integrations/copilot-cli. The full list is the "API Gateway integrations" section of https://docs.mindlogic.ai/llms.txt.

## Step 3 — Verify

```bash
curl -H "Authorization: Bearer $FACTCHAT_API_KEY" "https://factchat-cloud.mindlogic.ai/v1/gateway/models/"
```

Do not proceed until this returns a model list. On 401, tell the user the key is invalid or belongs to a different FactChat deployment than the one this prompt came from (https://factchat-cloud.mindlogic.ai); they need a key issued by this deployment.

## Step 4 — Before answering questions about the platform

Read, in this order: https://docs.mindlogic.ai/llms.txt (index of every page), https://docs.mindlogic.ai/AGENTS.md (URL shapes and Markdown negotiation), https://docs.mindlogic.ai/openapi.json (every gateway endpoint). Any docs page is also available as Markdown by appending `.md` to its URL.

Finally, tell the user which harness you configured and which models the verification returned. Usage is billed to the FactChat account that created the key.
