# Quickstart

## 1. Create a key

Open the Developer Portal in the AfterLib app, create an API key, and store the full `al_live_...` value somewhere secure.

API keys are shown once. If a key is exposed, revoke it and create another one.

## 2. Confirm the connection

```bash
export AFTERLIB_API_KEY="al_live_replace_me"

curl https://api.afterlib.com/v1/whoami \
  -H "Authorization: Bearer $AFTERLIB_API_KEY"
```

If this returns your AfterLib account, the key is working.

```json
{
	"authenticated": true,
	"authSource": "api_key",
	"user": {
		"userId": "00000000-0000-7001-8001-aa0000000001",
		"billingUserId": "00000000-0000-7001-8001-aa0000000001",
		"name": "Ada Lovelace",
		"emailAddress": "ada@example.com",
		"planId": "pro",
		"isTeamMember": false,
		"subscriptionStatus": "active"
	},
	"apiKey": {
		"id": "019e6387-e2e9-7478-9d6d-170158c523b0",
		"name": "Claude Desktop",
		"keyPrefix": "al_live_abc12345"
	},
	"oauthClientId": null
}
```

`user.name` and `user.emailAddress` can be `null` when AfterLib cannot resolve them for the connected account.

## 3. Check credits

```bash
curl https://api.afterlib.com/v1/credits \
  -H "Authorization: Bearer $AFTERLIB_API_KEY"
```

## 4. Search ads

```bash
curl https://api.afterlib.com/v1/ads/search \
  -H "Authorization: Bearer $AFTERLIB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "search": "running shoes",
    "limit": 10
  }'
```

## 5. Search websites

Website Library routes are no-credit in this phase:

```bash
curl "https://api.afterlib.com/v1/websites/domains?limit=10&search=running" \
  -H "Authorization: Bearer $AFTERLIB_API_KEY"
```

## 6. Work with collections

List collections first:

```bash
curl https://api.afterlib.com/v1/collections \
  -H "Authorization: Bearer $AFTERLIB_API_KEY"
```

Then read ads from a collection:

```bash
curl "https://api.afterlib.com/v1/collections/00000000-0000-0000-0000-000000000000/items?itemType=ads&limit=25" \
  -H "Authorization: Bearer $AFTERLIB_API_KEY"
```

Add an ad to a collection:

```bash
curl https://api.afterlib.com/v1/collections/00000000-0000-0000-0000-000000000000/items \
  -X POST \
  -H "Authorization: Bearer $AFTERLIB_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "itemType": "ads",
    "itemId": "1234567890"
  }'
```

The [collections guide](/collections) covers page collections, Website Library item types, and idempotent add behavior.

## Next steps

- Use [examples and recipes](/examples) for plain curl, JavaScript, TypeScript, PHP, and Python examples.
- Use the [websites guide](/websites) for Website Library domain and link routes.
- Use [request logs](/request-logs) when a response includes an error or an unexpected credit charge.