# TrendSwap auth.md — authentication for API and MCP clients

TrendSwap supports user API keys for agents and integrations. It does not operate an OAuth/OIDC authorization server, dynamic OAuth client registration, anonymous credential issuance, or an OAuth Protected Resource Metadata endpoint. Google/GitHub website login, when enabled, is for human website sessions only.

## Public access

No credentials are needed to read https://trendswap.app/openapi.json, https://trendswap.app/.well-known/api-catalog, https://trendswap.app/.well-known/agent-skills/index.json or to initialize the MCP server, list anonymous tools and call `list_templates` at https://trendswap.app/api/mcp. Anonymous MCP clients see only that tool.

## Public A2A access

Discover the read-only agent at https://trendswap.app/.well-known/agent-card.json. Send `POST https://trendswap.app/api/a2a` with `Content-Type: application/json` and `A2A-Version: 1.0`. This endpoint uses the A2A 1.0 JSON-RPC binding and requires no credentials. Do not include API keys in messages.

```json
{"jsonrpc":"2.0","id":1,"method":"SendMessage","params":{"message":{"messageId":"template-query-1","role":"ROLE_USER","parts":[{"text":"list_templates"}]}}}
```

Supported commands are `list_templates [search text]` and `get_integration_docs`. The synchronous `result.message` contains a public template catalog or integration guidance. This agent does not create tasks, stream responses, generate videos, purchase credits, or support payment mandates. An absent version header means A2A 0.3 and is rejected by this 1.0 interface.

## Provisioning a user API key

1. The account owner signs in at https://trendswap.app/sign-in using a supported website sign-in method. New owners can register at https://trendswap.app/sign-up and complete any required email verification.
2. Open https://trendswap.app/settings/apikeys and create a named user API key. This existing page calls `POST https://trendswap.app/api/apikeys` with the owner's authenticated website session and JSON body `{"title":"My integration"}`. A session is required: this is not an anonymous agent registration endpoint.
3. Copy the returned `sk_` key and store it in the integration's secret store. The authenticated owner can also copy recoverable keys again from the key list. User keys are persisted (encrypted when the deployment configures CONFIG_ENCRYPTION_KEY); validation uses their SHA256 hashes. Never expose a key in a browser tool, URL, source file or log.

To list keys, the same owner session can call `GET https://trendswap.app/api/apikeys`. Responses use the application's `{code,message,data}` envelope; check `code`, not only HTTP status. There is no separate agent account-registration or token-exchange API.

## Credential use

Send `Authorization: Bearer <your-user-api-key>` or `X-API-Key: <your-user-api-key>` over HTTPS to authenticated product REST endpoints or https://trendswap.app/api/mcp. These are API-key credentials, not OAuth access tokens. Admin agent keys do not authenticate the product API.

For MCP Streamable HTTP POST requests send `Content-Type: application/json` and `Accept: application/json, text/event-stream`. Start with MCP `initialize` and use the negotiated protocol version. A valid key adds `get_credits_balance`, `create_generation_job` and `get_job_status` to the tools list. Invalid keys do not unlock authenticated tools. REST operation details are documented at https://trendswap.app/openapi.json and https://trendswap.app/docs/.

User keys act as their owning user; there are no per-key OAuth scopes. Generation consumes the owner's existing credits and must be explicitly authorized by that owner. Reading the catalog or discovering tools does not generate videos or purchase credits.

## Revocation and rotation

Delete a key at https://trendswap.app/settings/apikeys. The page calls `DELETE https://trendswap.app/api/apikeys?id=<key-id>` with the owner's website session. Deleted keys cease to validate. Rotate by creating a replacement, updating the integration's secret store, then deleting the old key. There is no OAuth revocation URI or refresh-token flow.
