# Trial key for agents

One call, no account, and an agent has a key that works for 24 hours.

```text
POST https://api.millionshort.com/v1/keys/agent
```

Returns a short-lived API key with a small credit grant. It is the only `/v1` call that needs no key, and it is meant for an agent that wants to try the API with no person at hand to sign up. For anything lasting, create a key in the [dashboard](https://millionshort.com/app/).

## Request

| Field | Type | Notes |
|---|---|---|
| `agent` | string, up to 60 characters | Required. The agent's name. |
| `purpose` | string, up to 200 characters or null |  |

```bash
curl https://api.millionshort.com/v1/keys/agent \
  -H "Content-Type: application/json" \
  -d '{ "agent": "my-agent", "purpose": "trying the search API" }'
```

```python
from millionshort import MillionShort

key = MillionShort().create_agent_key("my-agent").api_key
client = MillionShort(api_key=key)

r = client.search("sourdough starter hydration", num_results=3)
print(r.results[0]["title"], r.usage.credits)
```

```ts
import { MillionShort } from 'millionshort';

const { api_key } = await new MillionShort().createAgentKey('my-agent');
const client = new MillionShort({ apiKey: api_key });

const r = await client.search('sourdough starter hydration', { numResults: 3 });
console.log(r.results[0]?.title, r.usage?.credits);
```

## Response

`data` holds the key. It is shown once: keep it for the session, and do not write it into a file.

| Field | Type | Notes |
|---|---|---|
| `api_key` | string | The `ms-...` key, shown exactly once. |
| `tier` | `trial` |  |
| `rate_limit` | string |  |
| `expires_in_days` | integer | `expires_in_hours` rounded up to whole days. |
| `expires_in_hours` | integer |  |
| `expires_at` | string | When the key stops working. |
| `team_id` | string |  |

## What a trial key can do

| | |
|---|---|
| Credits | 25. They cannot be topped up |
| Lifetime | 24 hours. `expires_at` gives the exact time |
| Endpoints | Everything a normal key can call: search, sources, domain info |
| Sources per search | Up to 5 |
| Results per search | Up to 50 |
| `explain` | Yes |
| Renewal | None. When it ends, create a key in the dashboard |

## Limits

Trial keys are limited per network address and in total per day. Past a limit the call answers `429`. All free and trial use together also has a daily ceiling; when it is reached, trial keys get `429 CAPACITY` until midnight UTC, and paid keys are not affected.

The exact numbers are not published and can change. An agent that is refused should stop and ask its person for a key.

## Cost

Free. Searches made with the key draw on its 25 credits at the usual rates.

## Errors

`400 INVALID_PARAM` (no `agent`, or a value that is too long), `404` when trial keys are switched off, and `429` past a limit. See [Errors](https://millionshort.com/docs/errors).

## For the agent reading this

1. Call this endpoint once. Keep the key in memory or in an environment variable for the session.
2. Send it as `Authorization: Bearer <key>` on every other call.
3. Watch `usage.credits` on each response; you have 25.
4. When you get `401 AUTH_INVALID_KEY` after it worked before, the key has expired. Tell your person; do not ask for another in a loop.

The plain-text version of these steps is [auth.md](https://millionshort.com/docs/auth.md).
