# API authentication

How to authenticate requests to the inFlow API.

## Authentication methods

Use public keys for visitor submissions, session tokens for the dashboard, and temporary integration credentials for coding agents.

**Integration key (ik_…)** — local coding-agent credential for /api/agent-integration. Explicitly grants one or several businesses, with per-business form scope, approved domains, and optional lead read permission. Discovery needs no business header; every other request requires X-Business-Id. See /docs/agent-integration. **Legacy authoring key (fa_…)** — draft-only, one business, /api/form-authoring; cannot read leads or register domains.

**Public key (pk_…)** — for browser-facing endpoints (form submissions, showcase rendering, AI chat). Sent as an `Authorization: Bearer pk_…` header. Enforces origin restrictions via environments and allowed domains. Cannot access administrative endpoints.

**Session token (JWT)** — user authentication for dashboard requests. Sent as an HTTP-only cookie or `Authorization: Bearer <jwt>` header. X-Business-Id selects a business; current membership and resource permissions authorize each operation. A session is not a scoped integration credential to hand to an external agent.

## Public key endpoints

Public key auth is used for embedding inFlow widgets on third-party sites. It identifies a business but not an individual user. Endpoints that accept public key auth:

1. `POST /api/leads` — form submissions
2. `GET /api/v1/ssr/showcase/:id` — showcase SSR rendering
3. `GET /api/v1/ssr/showcase/:id/posts/:slug` — single post
4. `GET /api/public-ai/config` — published visitor agent configuration
5. `POST /api/public-ai/chat` and `POST /api/public-ai/chat/stream` — visitor chat
6. `GET /api/forms/public/:id` — published form definition

> **Note:** When Origin is supplied, public-key resolution checks the configured environment, legacy origin rules, or same-business hosted sites. Lead and visitor-chat writes additionally require a validated Origin. Public reads do not all require Origin. An agent can construct an Origin header, so origin admission is not proof of machine identity or administrative authority.

## Making an authenticated request

```ts
// Public key auth
const res = await fetch("https://api.inflow.build/api/leads", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer pk_67a1b2c3d4e5f6a7b8c9d0e1",
  },
  body: JSON.stringify({
    formId: "67d4...",
    responses: [],
  }),
});

const data = await res.json();
```

For session-authenticated endpoints (dashboard, admin), the server uses HTTP-only cookies managed by the login flow. Your frontend code calls the API normally — cookies are sent automatically.

## Error responses

| Status | Meaning |
| --- | --- |
| 401 | Missing or invalid API key |
| 403 | Origin, business scope, permissions, or feature access denied; inspect the endpoint's response |
| 429 | Rate limit exceeded |
