# Sign up from an agent

Page: https://galatea.co/api/docs/agent-signup

An agent signs its human up on its own, pays for credit over the Machine Payment Protocol and receives one key. No person has to be involved.

This route is for software. An agent can create an account for the human it works for, create that human's organization, buy credit with a card and receive one API key, with nobody in the loop. It needs no account and no key to start: the route is open to anyone, and the first pass is where the agent learns what to pay. A signed-in person is refused here, because a person creates a key on the dashboard.

The endpoint is POST https://galatea.co/api/agent/signup. Send Content-Type: application/json and an Idempotency-Key. The key is required. One key names one signup, and replaying it answers with the first result and never charges again.

## The two passes

Payment runs over the Machine Payment Protocol, in two passes. In the first the request carries no payment credential, so the platform answers 402 Payment Required with a challenge in the WWW-Authenticate header and a JSON body naming the amount in cents, the currency and the method. The challenge is signed, so the client cannot change the amount it is asked to pay, and the signature binds the challenge to this service, so a credential minted for somewhere else does not pass.

The client pays that challenge at its own payment provider, which returns a payment token, and sends the second pass: the same body, the same Idempotency-Key, and a payment credential that carries the token. The platform charges the card once, creates the account, the organization and the key, and answers 201.

Every refusal that can be made without moving money happens before the charge: the body, the address, the caller's own limits, the token's currency, expiry and amount, and the card's own limit. A refused signup therefore writes nothing, and a declined card leaves the address free so the agent can fix the card and retry with a new token.

## A client

The two passes are a loop: send the request, and when the answer is 402, pay the challenge it carries and send the request again with the credential. This is the shape with the mppx client, for a card the agent is authorized to spend from.

```typescript
import { Mppx, stripe } from "mppx/client";

const body = {
  email: "ada@example.com",
  name: "Ada Lovelace",
  org_name: "Ada's lab",
  top_up_cents: 1000,
};

const mppx = Mppx.create({
  methods: [
    stripe({
      // A card must be minted into a token by the one who holds the Stripe
      // secret key, so the agent's own service does it: the client sends the
      // challenge's parameters and gets a token back.
      createToken: async (params) => {
        const minted = await fetch("https://agent.example/mint-token", {
          method: "POST",
          headers: { "content-type": "application/json" },
          body: JSON.stringify(params),
        });
        const { spt } = await minted.json();
        return spt;
      },
      paymentMethod: "pm_card_visa",
    }),
  ],
});

// One Idempotency-Key for the whole signup. Both passes carry the same key.
const signup = () =>
  fetch("https://galatea.co/api/agent/signup", {
    method: "POST",
    headers: {
      "content-type": "application/json",
      "idempotency-key": "8f6b1c2e-3d4a-4b5c-9e7f-0a1b2c3d4e5f",
    },
    body: JSON.stringify(body),
  });

const answer = await mppx.fetch(signup);
const result = await answer.json();
// result.key.secret is the key, shown once.
```

## The request body

Fields of the signup request..

| Field | Type | Notes |
| --- | --- | --- |
| email | string | Required. The address the account is for: the human the agent works for. |
| name | string | Optional. The human's display name. Defaults to the part of the address before the at sign. |
| org_name | string | Required. The organization's name. The organization is created now and the human owns it. |
| top_up_cents | integer | Required. The credit to buy, in US cents, from 1000 (10 dollars) to 100000 (1000 dollars). |

## The answer

- user_id and org_id: the account and the organization that were created. The human owns the organization and can sign in to it.
- key.id, key.name and key.secret: one API key for the organization. The secret is shown exactly once, here, and cannot be read again. Mint another key from the dashboard if it is lost.
- payment.payment_intent, payment.amount_cents and payment.card: brand and last four digits only. No card number or fingerprint is ever returned.
- grants: every credit grant the signup posted, each with its reason, its amount and whether it was posted. The starter grant for a card that has already been used reports posted false and why_not.
- credits_url: where the balance lives. The balance is computed from the ledger on read, and is not part of the signup answer.

A 201 carries a Payment-Receipt header naming the payment. A replayed Idempotency-Key answers 200 with replayed true, the identifiers, the balance and no key secret: the first answer was the only time the secret was readable.

## Errors

Every status this route answers, and what it means..

| Status | Code | When | Retry |
| --- | --- | --- | --- |
| 400 | bad_request | The body is not JSON, a field is missing or out of range, the content type is not application/json, or the Idempotency-Key is missing or too long. | After fixing the request. |
| 402 | payment_required | The request carries no payment credential, or the credential, the token or the money is not usable: an unknown, spent, expired or under-sized token, another currency, a challenge that does not verify, or a card over its own limit. Pay the challenge and send it again. | With a credential. |
| 402 | payment_failed | The credential was good and the card was declined. Nothing was created. The decline_code in the body names the reason Stripe gave. | With another card. |
| 402 | requires_action | The card needs the payer to act, such as a bank confirmation this route cannot complete. Nothing was created. | With another card. |
| 403 | forbidden | The caller is a signed-in person. This route is for agents; a person creates a key on the dashboard. | No. |
| 409 | conflict | An account already exists for that address. Nothing was charged. If a payment had already been taken for it, it has been returned. | Sign in with that account instead. |
| 429 | rate_limited | A limit above this caller or this card was reached. Retry-After says how long to wait. | When Retry-After allows. |
| 503 | internal | Signup is not configured on this environment: the payment key is missing or is a live key, which this platform refuses in test mode. | No. |

## Limits and abuse

- Per address: at most 5 signups an hour.
- Per client: at most 20 signups a day. A caller that presents an Access service token is counted by that token; every other caller is counted by its address.
- Per card, counted by the card's fingerprint: at most 3 organizations every 30 days.
- The starting grant is once per card, ever. The second organization paid for with the same card is credited the credit it bought and not the starting grant, and the answer says so.

Nothing computed is stored. The limits above are counts over the signup rows, read when a request arrives, and credit is folded from the ledger on read. The signup row holds inputs only: which caller, which address, which card (as a hash, never the fingerprint itself), which payment and when.

## A test token

Stripe's test mode mints a shared payment token without a browser, so the whole flow can be scripted. In the Stripe sandbox the token is made with a test card:

```shell
curl https://api.stripe.com/v1/test_helpers/shared_payment/granted_tokens \
  -u "$STRIPE_SECRET_KEY:" \
  -H "Stripe-Version: 2026-09-30.preview" \
  -d payment_method=pm_card_visa \
  -d "usage_limits[currency]=usd" \
  -d "usage_limits[max_amount]=1000" \
  -d "usage_limits[expires_at]=$(( $(date +%s) + 3600 ))"
```

The pm_card_visa test card always succeeds. pm_card_visa_chargeDeclined always declines, which is how the payment_failed answer above is reproduced without a real card.

This route is on galatea.co, the platform host, and not on the public key-authenticated API at api.galatea.co. It is the one call in the flow that mints a key rather than using one, so it is also the one that takes a payment.
