Skip to content

agent-tenants

Terminal window
npx skills add https://github.com/crystallizeapi/ai --skill agent-tenants

Crystallize Agent Tenants

An agent with no Crystallize account gets a working tenant and an access token from one unauthenticated HTTP call. It builds in the tenant with the normal APIs, then hands it to a human through an ordinary tenantAdmin invite. A tenant no human joins is deleted 72 hours after it was provisioned, with everything in it.

So the user does not sign up first, and does not create an access token for you. You provision, build, and send them one link.

Before you provision

  • The user already has a tenant? Use it: ask for its identifier and an access token. Do not provision.
  • You already provisioned one for this project? Reuse it (read it back from where you stored it in step 1), unless its expiresAt has passed with no human on it: then it is gone, and you provision again. Every call makes a new tenant, a new agent user and a new token, and an unused one lingers until it expires.
  • Otherwise, tell the user in one line what is about to happen: a tenant named after their project is created now, and deleted in 72 hours unless they open the invite link you will give them.

The flow

1 Provision POST /agents/tenants, no auth → tenant, access token, expiresAt, apiUrl
2 Build Core API at apiUrl with that token → shapes, items, everything else
3 Invite createInviteToken(role: "tenantAdmin") → invite token
4 Hand off the App's /get-access?token=… link → the human joins as tenantAdmin
5 Check the tenant's members on the PIM API → a human tenantAdmin = claimed
6 Serve publish, igniteDiscoApi, credentials → a storefront can read it

Only step 1 is specific to agents. Steps 2 to 6 are the API a human tenant admin already uses, and step 6 applies to every new tenant.

Used for Host
Provisioning and Core API https://api.crystallize.com
App (the invite link) https://app.crystallize.com
PIM API (members) https://pim.crystallize.com/graphql

1 · Provision

Terminal window
curl -s -X POST https://api.crystallize.com/agents/tenants \
-H 'content-type: application/json' \
-d '{"name":"Acme Coffee","identifier":"acme-coffee","source":"claude-code"}'
Field Required Rules
name yes String, 1 to 100 characters once trimmed. The tenant’s display name.
identifier no String, 1 to 100 characters. Lowercased; anything outside a-z 0-9 - becomes -. Without it (or if nothing usable remains) it comes from name, else agent-<8 hex>.
source no String, 1 to 100 characters. Who is provisioning (claude-code, cursor). Shown as the agent user’s name.

Any other key is ignored, omitDefaultShapes included. Values that are not plain strings are refused with 400.

Response, 201 Created:

{
"tenant": { "id": "6adbb89b790dd26b73debb6b", "identifier": "acme-coffee", "name": "Acme Coffee" },
"accessToken": { "id": "5a495b4547e21721ecca", "secret": "<shown once>" },
"expiresAt": "2026-10-26T19:42:19.887Z",
"apiUrl": "https://api.crystallize.com/@acme-coffee"
}
  • Store all of it now. The secret is returned this once and cannot be read again: lose it and you lose the tenant. Write the values where the project keeps secrets, never in a commit: a .env that .gitignore lists (add the line if it is missing).

    Terminal window
    CRYSTALLIZE_TENANT_ID=6adbb89b790dd26b73debb6b
    CRYSTALLIZE_TENANT_IDENTIFIER=acme-coffee
    CRYSTALLIZE_API_URL=https://api.crystallize.com/@acme-coffee
    CRYSTALLIZE_ACCESS_TOKEN_ID=5a495b4547e21721ecca
    CRYSTALLIZE_ACCESS_TOKEN_SECRET=<secret>
    CRYSTALLIZE_TENANT_EXPIRES_AT=2026-10-26T19:42:19.887Z
  • Use the returned identifier, not the one you sent. When the wanted one is taken, a number from 1 to 200 is appended (acme-coffee-37).

  • apiUrl is the tenant’s Core API endpoint. Every call in steps 2 and 3 goes there.

  • expiresAt is 72 hours after provisioning. The invite in step 3 must expire no later than this.

2 · Build with the token

You are a tenant admin like any other: every Core API call goes to apiUrl with the two token headers. Nothing about an agent tenant is special.

Terminal window
curl -s "$CRYSTALLIZE_API_URL" \
-H 'content-type: application/json' \
-H "X-Crystallize-Access-Token-Id: $CRYSTALLIZE_ACCESS_TOKEN_ID" \
-H "X-Crystallize-Access-Token-Secret: $CRYSTALLIZE_ACCESS_TOKEN_SECRET" \
-d '{"query":"{ shapes { edges { node { identifier name type } } } }"}'
# → { "data": { "shapes": { "edges": null } } }

The tenant starts with no shapes. It does have a VAT type, a stock location, a price variant and a catalogue root, like any new tenant. So the first build step is usually a shape. Mutations return a union: the type on success, or an error implementing BasicError, so always select both.

mutation {
createShape(
input: {
identifier: "coffee"
name: "Coffee"
type: product
components: [
{ id: "origin", name: "Origin", type: singleLine }
{ id: "tasting-notes", name: "Tasting notes", type: richText }
]
}
) {
__typename
... on Shape {
identifier
}
... on BasicError {
errorName
message
}
}
}

From here on, the other Crystallize skills apply unchanged with this token: [[content-model]] to design shapes, [[mutation]] and [[query]] for the Core API, and [[js-api-client]] in code (tenantIdentifier is the returned identifier).

Prefer one mass operations file over a string of one-off mutations for anything beyond a first shape. Put the shapes, pieces, folders and items in a [[mass-operations]] file and run it on the tenant with the same token. Until a human claims it, the tenant is disposable. With the file kept in the project, a tenant that expires unclaimed, or a build the user wants redone, is one new tenant and one replay away.

3 · Create the claim invite

The claim is an ordinary invite: a tenantAdmin invite token on the tenant, created with the same token. Pass the tenant’s expiresAt as the invite’s expiresAt.

Terminal window
curl -s "$CRYSTALLIZE_API_URL" \
-H 'content-type: application/json' \
-H "X-Crystallize-Access-Token-Id: $CRYSTALLIZE_ACCESS_TOKEN_ID" \
-H "X-Crystallize-Access-Token-Secret: $CRYSTALLIZE_ACCESS_TOKEN_SECRET" \
-d @- <<'EOF'
{
"query": "mutation Invite($expiresAt: DateTime) { createInviteToken(role: \"tenantAdmin\", expiresAt: $expiresAt) { __typename ... on InviteToken { id token expiresAt } ... on BasicError { errorName message } } }",
"variables": { "expiresAt": "2026-10-26T19:42:19.887Z" }
}
EOF
# → { "data": { "createInviteToken": { "__typename": "InviteToken", "id": "…", "token": "<invite token>", "expiresAt": "…" } } }
  • The claim invite’s role must be tenantAdmin, for whoever will own the tenant: the user, or someone they name. Only a human tenantAdmin claims the tenant. An invite with any other role lets a human in and keeps the tenant from deletion, but does not claim it: send one on top of the admin invite, never instead of it.
  • expiresAt is optional in the schema; send it anyway, no later than the tenant’s. An invite that outlives the tenant is useless. A date in the past is accepted and gives a dead link: if a human has kept the tenant past its deadline, send a future date.
  • Errors come back in the result, not as HTTP errors. An unknown role gives RoleNotFoundError instead of InviteToken.
  • An invite works once. A second human needs a second invite, and a used link only shows an “already redeemed” error. You can create a new invite at any time, for instance when one has expired or been used.

4 · Hand the invite to the human

https://app.crystallize.com/get-access?token=<invite token>

The human opens it, signs in or signs up, and joins the tenant as tenantAdmin. You cannot redeem it for them: invite redemption is refused to agent users. Whoever opens the link becomes tenantAdmin, so give it only to the person who will own the tenant, and keep it out of commits.

Always give the deadline with the link, as a date and time (the user’s time zone if you know it, else UTC):

Your Crystallize tenant Acme Coffee (acme-coffee) is ready. Open this link to sign in and take it over: https://app.crystallize.com/get-access?token=… Open it before Monday 26 October 2026, 19:42 UTC. If no one has joined by then, the tenant and everything in it is deleted.

If the user cannot open it in time, someone they name can open a tenantAdmin link instead and claim the tenant.

What happens next needs no call from you:

  1. The App redeems the token (redeemInviteToken) and the human becomes tenantAdmin on the tenant.
  2. At the next cleanup run, within 2 hours, Crystallize sees a human tenantAdmin and the tenant is claimed: from then on it can never be removed automatically.
  3. The human is subscribed to the newsletter under the usual signup rules.

5 · Check whether the human joined (optional)

The claim happens whether or not you check. Check when the user says they have joined, so you can confirm it worked; do not poll on a loop. The Core API has no user queries and no API reads an invite back, so the tenant’s members on the PIM API are the signal. Same two token headers:

query Members($id: ID!) {
tenant {
get(id: $id) {
users {
role
user {
id
firstName
lastName
email
kind
}
}
}
}
}

Variables: { "id": "6adbb89b790dd26b73debb6b" } (the tenant.id from step 1). Before the human joins, the only member is the agent: role: "tenantAdmin", firstName: "Agent", email: null, kind: "agent". Once they join, a second member appears with role: "tenantAdmin" and kind: "human", with their name and email.

6 · Get it ready to serve

A built tenant is not yet one a storefront can read. Do this before you hand over, or tell the user what is left:

  1. Settings first. Languages, the default language, VAT types, price variants, stock locations and pipelines are split between the Core API and the legacy PIM API (same token headers). A fresh tenant already has en, a No Tax VAT type, a default price variant in EUR and a default stock location.
  2. Publish the items. Discovery indexes only published content, and publishItem returns before the item is published.
  3. Ignite Discovery once with igniteDiscoApi(stacks: opensearch) on the Core API. Until then Discovery answers HTTP 404 with “There is no ignited Tenant” in a plain JSON body. Ignite again after new shapes, components, stock locations or vocabularies.
  4. Credentials. The storefront’s server needs the static token if Discovery or Catalogue is restricted, and an access token pair to mint Shop API tokens (one scoped to the tenant is enough). Core stays out of the request path.
  5. Publish webhooks (concern: "items", plural) if the storefront caches Discovery reads.

Every setting with its API and call, the getMany answer shapes, the ignite, the credentials table and a webhook example are in references/tenant-setup.md. The storefront side is in [[storefront]].

Rules

Topic Rule
Lifetime expiresAt = provisioning + 72 h. A cleanup runs every 2 hours, so an unclaimed tenant goes between 72 h and about 74 h later, with all its content, the agent user and its token.
What keeps a tenant Any human with a role on it. A human tenantAdmin claims it for good. A human with a lesser role keeps it from deletion but does not claim it: it waits for a human admin.
Promoting a human Promoting a lesser-role human to tenantAdmin claims the tenant: setUserRole(userId: "<id from step 5>", role: "tenantAdmin") on the Core API, or the user list in the App.
Nothing else No call extends the 72 hours. Only a human joining keeps the tenant.
After the claim The agent stays tenantAdmin and its token keeps working. The human can remove the agent user in the App; the cleanup then deletes it and its tokens.
One tenant per call An agent cannot create tenants any other way (createTenant on /@me, PIM tenant.create), copy a tenant, or redeem invites. Another tenant is another POST /agents/tenants.
The agent user Named Agent <source>, no email, and no one can log in as it. It acts only through its token, which works on its own tenant only.
Rate limit Provisioning has its own limit, per IP and across all callers, on top of the per-IP limit on every call (429). On a shared cloud IP you can hit it with few calls of your own.

Errors

Provisioning answers plain HTTP errors with a JSON body, { "message": "…", "statusCode": 400 }. Authenticated GraphQL calls answer HTTP 200 with the error inside the result union (__typename, errorName, message).

Call Status Message What to do
Provision 400 The body must be a JSON object. Send a JSON object with content-type: application/json.
Provision 400 name is required and must be a string of 1 to 100 characters. Fix name. An object or a number in name gets the same answer.
Provision 400 identifier must be a string of 1 to 100 characters. Fix or drop identifier.
Provision 400 source must be a string of 1 to 100 characters. Fix or drop source.
Provision 409 That tenant identifier was just taken. Please retry. Retry the same call once: a new identifier is picked. Nothing was created.
Provision 500 Provisioning failed (trace <id>). Retry later; give the trace id to Crystallize support if it repeats. Half-created is cleaned.
Provision 503 Crystallize cannot provision more agent tenants right now. … At capacity. Retry later, or have the user create a tenant and give you an access token.
Provision 404 none The endpoint is not deployed on that host. Tell the user.
Any 429 none Too many requests. Provisioning is also limited across all callers: wait minutes, then retry.
Any call, once the tenant is deleted 403 Invalid access token pair provided The tenant, its agent user and its token are gone. Provision again and replay your build.
createInviteToken 200 RoleNotFoundError: Role not found: <role> (tenant id <id>) The claim invite takes tenantAdmin; any other role must exist on the tenant.
Agent-forbidden: /@me createTenant, invite redemption, tenant copy 200 UnauthorizedError: This operation is not available to agent users. Do not retry. Create tenants with step 1 only, and let humans redeem invites.

Common mistakes

Mistake What happens Instead
Sending the user to sign up and create an access token The friction this endpoint removes Provision, build, then send one invite link
Not storing the secret right away The tenant is unreachable: the secret cannot be read again Write every value to the project’s secrets in step 1
Calling /@<the identifier you sent> The calls fail when the identifier was taken and got a suffix Use the returned identifier and apiUrl
Provisioning again to start over while the tenant is alive A second tenant, agent user and token; the first lingers for 72 h Fix or recreate the shapes in the tenant you have
Building only with one-off mutations An expired tenant takes the whole build with it Keep the build as a mass operations file and replay it into a new tenant
Sending only an invite with another role The human gets in and keeps the tenant, but it is not claimed Always create a tenantAdmin invite for whoever will own it; others go on top
An invite with no expiresAt, or one past the tenant’s A link that still looks valid after the tenant is gone Pass the tenant’s expiresAt
Giving the link without the deadline The user opens it on day four and finds nothing Always state the date and time with the link
Saying “it’s yours, nothing to transfer” after provisioning The user never opens the invite, and the tenant is deleted The tenant is the agent’s until a human tenantAdmin joins
Handing over without publishing and igniting The storefront gets “There is no ignited Tenant” or no hits Publish, igniteDiscoApi(stacks: opensearch), then hand over (step 6)

Related: [[permissions]] for roles and access tokens once the human owns the tenant.


Reference Details

Tenant setup: which API creates what

Getting a tenant ready to serve a storefront, whether you provisioned it as an agent or a human gave you an access token. The settings are split across the Core API (https://api.crystallize.com/@{tenant}) and the legacy PIM API (https://pim.crystallize.com/graphql, most calls take tenantId, the id and not the identifier). Both take the same access token pair.

What a fresh tenant has

Setting On a new tenant
Languages en, the default. It can’t be removed: “Cannot add, remove or modify system languages (en)”
VAT types One, No Tax at 0 %. A seed that matches VAT types by percent reuses it
Price variants default, in EUR. Its identifier can’t be renamed and the variant can’t be removed; change its name
Stock locations default
Pipelines None. pipeline.getMany answers edges: null, not []
Shapes None on an agent tenant (see SKILL.md step 2)
Discovery index None. Discovery answers “There is no ignited Tenant” until the first ignite

A tenant that sells only in Norwegian keeps en and makes no the default.

Setting → API → call

Setting API Call
Languages Core createTenantLanguage(input: { code, name }), updateTenantLanguage, deleteTenantLanguage
Default language and currency PIM tenant { update(id, input: { defaults: { language, currency } }) }, after the language exists
VAT types PIM vatType { create(input: { tenantId, name, percent }) }; update(id, input: { name, percent })
Price variants PIM priceVariant { create(input: { tenantId, identifier, name, currency }) }
Stock locations PIM stockLocation { create(input: { tenantId, identifier, name }) }
Order pipelines and stages PIM pipeline { create(input: { tenantId, name, stages }) }, addStage, updateStage
Markets PIM market { create(input: { tenantId, identifier, name, customerIdentifiers }) }
Subscription plans PIM subscriptionPlan { create } (see [[subscriptions]])
Custom views (tenant frontends) PIM tenant { setPreferences(tenantId, input: { frontends: [{ name, url }] }) }
Customer groups Core createCustomerGroup (see [[mutation]])
Booking policies Core createBookingPolicy (see [[bookable-resources]])
Webhooks Core createWebhook(input) (below)
Discovery index Core igniteDiscoApi(stacks: opensearch) (below)
Static auth token, signature secret Core read tenant { staticAuthToken signatureSecret }; rotate with regenerateTenantSecrets

Traps:

  • UpdateVatTypeInput rejects tenantId, while CreateVatTypeInput requires it. A seed that sends the same input to both fails on update.
  • The default language can be changed on an empty tenant: createTenantLanguage, then PIM tenant.update with defaults.language. Do it before content exists. The default language is the one Discovery returns relations in.
  • The Core API now also has updateTenant(input: { defaults }) and createPriceVariant. The PIM calls above are the ones the builds used.
  • getMany answers differ. pipeline.getMany and market.getMany return a connection (edges { node { id name stages { id name } } }), and edges is null on an empty tenant. priceVariant.getMany and stockLocation.getMany return plain lists. VAT types are read from tenant { get(id) { vatTypes { … } } }.
  • Pipeline and stage ids are what the Shop API returns on orders (pipelines { identifier stage }). A storefront that shows stage names reads pipeline.getMany at build time and writes the id → name map into its data, not on every request.

The first ignite

A tenant has no Discovery index until igniteDiscoApi runs once. Until then Discovery answers HTTP 404 with a plain JSON body, not a GraphQL errors array:

{ "success": false, "message": "There is no ignited Tenant for …" }

A probe that looks only at errors misses it. Ignite from Core and pass the stack:

mutation {
igniteDiscoApi(stacks: opensearch)
}

It took about a minute on a new tenant. Ignite again after you add:

  • shapes or components (a new field can need a second ignite minutes later; check __type(name: "<shape>") on Discovery before shipping code that queries it),
  • stock locations (their <location>Stock fields appear only after a re-ignite),
  • vector vocabularies (see [[vector-ranking]]).

Ignite indexes what is published. Publish first, then ignite. A component made discoverable after publishing needs the items published again; a re-ignite alone re-indexes the old documents. Querying new fields is covered in [[query]].

Storefront credentials

What the storefront’s server needs, and where it comes from. The API for each storefront task is in [[storefront]].

API Credential Where to get it
Discovery None while open (the default). The static token when Settings → API access restricts it tenant { staticAuthToken } on Core, or the App
Catalogue Open, static token or token pair, per Settings → API access As above
Shop API A JWT from POST https://shop-api.crystallize.com/{tenant}/auth/token with { scopes, expiresIn } Minted on the server with an access token pair, scoped to the tenant or not (see [[permissions]])
Core A tenant-scoped pair, for seeds, imports and webhook receivers only. Never in the storefront request path A dedicated integration user (see [[permissions]])
  • A tenant-scoped token mints Shop API tokens for its own tenant only. Another tenant’s /auth/token answers 400 “User is not a member of tenant X”, even for a member: check the token’s scope before its membership. Once a human owns the tenant, they create a tenant-scoped token on a dedicated user.
  • An open Discovery is public. Everything it indexes, every price variant and every market’s price list included, is readable by anyone. Restrict it, or keep confidential terms out of it.
  • The Shop API JWT is per tenant, not per shopper. Keep it on the server, cache it, and refresh it before it expires.

Webhooks for cache revalidation

A storefront that caches Discovery reads clears its cache when items are published. The publish webhook is a Core setting:

mutation CreateWebhook($url: String!, $secret: String!) {
createWebhook(
input: {
name: "storefront-revalidate-publish"
concern: "items"
event: "publish"
method: POST
url: $url
headers: [{ name: "x-revalidate-secret", value: $secret }]
preserveDefaultPayload: true
graphqlQueryTarget: next
graphqlQuery: "query ($id: ID!, $language: String!) { item(id: $id, language: $language) { ... on Item { id shapeIdentifier tree { path } } } }"
}
) {
... on Webhook {
id
}
... on BasicError {
errorName
message
}
}
}
  • The concern is items, plural. createWebhook accepts any concern and event string without validation: item, product or nope are all accepted, and they never fire. Add a second webhook with event: "unpublish".
  • The default payload has no path: { id, type, tenantId, language, userId, webhookId }. Add a graphqlQuery (it gets $id and $language; graphqlQueryTarget: next runs it against the Core API) and keep preserveDefaultPayload: true so the receiver gets both.
  • Debug through the invocations: webhooks { ... on WebhookConnection { edges { node { name concern event lastInvocation { start response { status } } } } } }, or the webhookInvocations query. A webhook that never shows an invocation has the wrong concern or event.
  • The receiver is a server route in the storefront that checks the secret header and clears the cache tag for the item (see [[storefront]]). Key the setup script on the webhook name, so a rerun updates instead of duplicating.


Crystallize AI