# auth.md

You are an agent that wants to call the Hydrafetch API on a user's behalf. This file describes how to obtain credentials and how to handle them safely.

Two hosts are relevant:

- **Resource server**: `https://api.hydrafetch.com`, the API you call (`/v1/web` for REST, `/mcp` for MCP).
- **Dashboard**: `https://app.hydrafetch.com`, where the user manages their account, keys and MCP connections.

## Current state

Hydrafetch does not support agentic registration. Signup sits behind a bot challenge, email verification needs the mailbox, and a paid plan needs a card. Those are deliberate, not gaps to route around. REST credentials are issued by the user out of band; MCP uses a browser OAuth flow the user completes themselves.

## Use the existing tooling first

Before you do anything credential-shaped, check whether the user has already wired Hydrafetch into your environment.

1. **MCP server**: if you speak remote MCP over Streamable HTTP, connect to `https://api.hydrafetch.com/mcp`. Authentication is OAuth 2.1 with PKCE: the user signs in and approves scopes in the browser, and you call tools without ever seeing a credential. Discovery: `https://hydrafetch.com/.well-known/mcp/server-card.json`. Tool catalogue, no auth required: `https://api.hydrafetch.com/mcp/tools`.
2. **An existing key in the environment**: if `HYDRAFETCH_API_KEY` is already set, or a project `.env` the user has told you to read contains one, use it.

If either is available, use it and stop. Do not ask the user for an API key you do not need.

## OAuth metadata

- Protected resource metadata (RFC 9728): <https://api.hydrafetch.com/.well-known/oauth-protected-resource>
- Authorization server metadata (RFC 8414): <https://api.hydrafetch.com/.well-known/oauth-authorization-server>
- Scopes: `web:scrape`, `web:extract`. A full-access grant is stored as `*`, so tools added later need no re-authorisation.

Both are mirrored on this domain at the same paths for discovery. The `issuer` inside them is authoritative and always points at the API host.

## The REST credential

The only REST credential is a Hydrafetch API key (prefix `hf_`), sent in the `X-API-Key` header. The user creates it in the dashboard under API Keys and supplies it through a secure channel.
The official SDKs read `HYDRAFETCH_API_KEY` from the environment themselves, so in a language that has one there is nothing to pass and nothing to store in code. Validate that the variable is set and fail loudly if it is not, rather than inventing a placeholder.

There is a second kind of key, and it is not for you. A *publishable* key (prefix `hf_pk_`) authenticates only the logo image endpoint, is designed to sit in a public web page, and is refused everywhere else. If the user hands you one, it will not authenticate a scrape, so ask for a secret key instead.

### How to pick the key up

Look in this order, and stop at the first that exists:

1. The `HYDRAFETCH_API_KEY` environment variable.
2. A `.env` file in the project the user has pointed you at.
3. A secret manager the user has already configured for this project.

If none exists, ask the user to copy their key from the dashboard and set `HYDRAFETCH_API_KEY`, then resume. Tell them where to go rather than asking them to paste it to you.

### Handling rules

- Never ask the user to paste a key into a chat transcript.
- Never write a key into source, logs, comments, commit messages or error output.
- Never send a key to any host other than the resource server above.
- If a key is exposed, tell the user to revoke it in the dashboard immediately.

## What you must not do

- Do not create an account on the user’s behalf.
- Do not attempt to solve or bypass the signup bot challenge.
- Do not purchase a plan, or enter card details, on the user’s behalf.

New workspaces get free credits on signup with no card, which is enough to evaluate the API before anyone pays for anything.

## See also

- Agent guide: https://hydrafetch.com/agents.md
- Pricing: https://hydrafetch.com/pricing.md
- API documentation: https://docs.hydrafetch.com
