> ## Documentation Index
> Fetch the complete documentation index at: https://enterprise-docs.crewai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Provisioning Organizations with the Admin API

> Create organizations and their owners from a script, and hand each organization credentials for the Platform API

## Overview

The Admin API lets a Factory install create organizations from a script instead of the admin panel. Each request creates an organization, its owner, and a service account inside that organization with administrator rights. The response returns that service account's credentials, which you then use with the [CrewAI Platform API](https://docs-platform.crewai.com/api/introduction) (`/api/v1`) to configure the organization, for example to add its environment variables.

The Admin API is available on Factory installs only. It is served under `/admin-api/v1` on your CrewAI Platform host.

```mermaid theme={null}
sequenceDiagram
participant Script as Your provisioning script
participant AMP as CrewAI Platform

Script->>AMP: 1. Exchange the Admin API credential for a token
Script->>AMP: 2. POST /admin-api/v1/organizations
AMP-->>Script: 3. Organization + its service account credentials
Script->>AMP: 4. Exchange the organization's credentials for a token
Script->>AMP: 5. Configure the organization through /api/v1
```

Two kinds of credentials are involved, and each works on one API only:

| Credential | Where it comes from | Works on |
| - | - | - |
| Admin API credential | **Admin panel > API Credentials** | `/admin-api/v1` |
| Organization service account (`crewai-org-provisioner`) | Returned when you create an organization | `/api/v1`, for that organization only |

## Before you start

* Complete the [Post-Installation](https://enterprise-docs.crewai.com/installation/post-installation.md) steps, including **Initialize Internal Organization** and **Grant Admin Panel Access**. Admin API credentials are created in the admin panel and belong to the install's internal organization.
* Decide how organization owners will sign in. If you pass `owner_external_id`, it must be the exact subject (`sub`) your identity provider issues for that user. See [Create an organization](#create-an-organization).

## Create an Admin API credential

1. Sign in to the admin panel at `https://<your-host>/admin`.
2. Open **API Credentials**.
3. Enter a **Name** that describes the integration, such as `provisioning-pipeline`, and click **Create credential**.
4. Copy the **Client ID** and **Client secret**. The secret is shown only once.

> [!WARNING]
>
> An Admin API credential acts across every organization on the install. Store its secret like an administrator password, in your secrets manager, and never in source control.

From the same page you can **Rotate secret** or **Revoke** a credential. Rotating replaces the secret immediately: the old secret and every token issued from it stop working at once, so update your scripts right after rotating.

## Get an access token

Exchange the credential for a short-lived access token with the OAuth 2.0 client credentials flow. This is the same token endpoint organizations use, described in [Service accounts](https://docs-platform.crewai.com/api/service-account).

```bash theme={null}
curl -X POST "https://crewai.yourdomain.test/oauth/token" \
  -H "Authorization: Basic $(printf '%s:%s' "$ADMIN_CLIENT_ID" "$ADMIN_CLIENT_SECRET" | base64)" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials"
```

```json theme={null}
{
  "access_token": "crewai_sacat_...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

Reuse the token until it is close to expiring rather than requesting one per call.

## Create an organization

```bash theme={null}
curl -X POST "https://crewai.yourdomain.test/admin-api/v1/organizations" \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Acme",
    "owner_email": "ada@acme.com",
    "owner_external_id": "00u1a2b3c4d5e6f7g8h9",
    "reference": "acme-1"
  }'
```

**name** `string` *required*

The organization's display name.

**owner\_email** `string` *required*

The email of the organization's owner. If a user with this email already exists on the install, that user becomes the owner; when you also pass `owner_external_id`, it must belong to that same user.

**owner\_external\_id** `string`

The owner's subject identifier (`sub`) in your identity provider, exactly as the provider issues it. The owner is matched by this value when they sign in.

If you leave it out, the owner is created with a temporary identifier, and the first person to sign in with `owner_email` through your identity provider claims the account. Pass it whenever you know the subject identifier.

**reference** `string`

Your own identifier for the organization, such as a customer or tenant ID. It must be unique on the install, and you can look organizations up by it later.

A successful request returns `201 Created`:

```json theme={null}
{
  "data": {
    "id": "9b2f6c1e-3d4a-4f5b-8c7d-1e2f3a4b5c6d",
    "name": "Acme",
    "reference": "acme-1",
    "owner": {"id": "4c3b2a19-8e7d-4c6b-9a5f-0e1d2c3b4a59", "email": "ada@acme.com"},
    "k8s_namespace": null,
    "created_at": "2026-11-15T20:11:08Z",
    "updated_at": "2026-11-15T20:11:08Z",
    "service_account": {
      "client_id": "...",
      "client_secret": "..."
    }
  }
}
```

The organization is created with:

* the owner as an **Owner** of the organization, in its **Administrators** team;
* a service account named `crewai-org-provisioner` in the **Administrators** team, whose credentials are in `service_account`.

> [!WARNING]
>
> The `client_secret` is returned only in this response. Store it before doing anything else. If it is lost, [rotate the credentials](#rotate-an-organizations-credentials).

`k8s_namespace` is the namespace the organization's automations deploy to when [Multi-Org Namespaces](https://enterprise-docs.crewai.com/features/multi-org-namespaces.md) is enabled, and `null` otherwise. Create that namespace before the organization deploys its first automation.

## Configure the new organization

Use the returned `client_id` and `client_secret` to get a token for the organization, exactly as in [Get an access token](#get-an-access-token), then call the [CrewAI Platform API](https://docs-platform.crewai.com/api/introduction). Because the service account is in the Administrators team, it can manage the organization from its first token.

For example, to add an environment variable the organization's automations can use:

```bash theme={null}
curl -X POST "https://crewai.yourdomain.test/api/v1/environment-variables" \
  -H "Authorization: Bearer $ORG_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"key": "OPENAI_API_KEY", "value": "sk-..."}'
```

Environment variables are write-only through the API: you can create, update, and delete them, but values are never returned. Creating a key that already exists returns `409 Conflict` with the existing variable's ID, so you can update it instead. See the Platform API reference for every field, including references to an external secrets manager.

## Find organizations

List the organizations on the install, optionally filtered by `name` or `reference`:

```bash theme={null}
curl -G "https://crewai.yourdomain.test/admin-api/v1/organizations" \
  -H "Authorization: Bearer $ADMIN_TOKEN" \
  --data-urlencode 'filter=reference = "acme-1"'
```

Results are paged. Pass `page_size`, and use the `next_page_token` from the response's `meta` as `page_token` to get the next page. `order_by=name` sorts by name.

```json theme={null}
{
  "data": [{"id": "9b2f6c1e-...", "name": "Acme", "reference": "acme-1", "...": "..."}],
  "meta": {"total_size": 1, "next_page_token": null}
}
```

Get a single organization by its ID:

```bash theme={null}
curl "https://crewai.yourdomain.test/admin-api/v1/organizations/$ORG_ID" \
  -H "Authorization: Bearer $ADMIN_TOKEN"
```

Listing and fetching never return service account secrets.

## Rotate an organization's credentials

```bash theme={null}
curl -X POST "https://crewai.yourdomain.test/admin-api/v1/organizations/$ORG_ID/credentials/rotate" \
  -H "Authorization: Bearer $ADMIN_TOKEN"
```

The response has the same shape as the create response, with the same `client_id` and a new `client_secret`. The previous secret, and every token issued from it, stops working immediately; there is no grace period.

## Errors

Errors use the CrewAI API error envelope, with a `code` and a `detail` for each error:

```json theme={null}
{
  "errors": [
    {"code": "conflict", "detail": "An organization with this reference already exists: 9b2f6c1e-3d4a-4f5b-8c7d-1e2f3a4b5c6d."}
  ]
}
```

| Status | Code | When |
| - | - | - |
| `400` | `bad_request` | `name` or `owner_email` is missing. |
| `401` | `unauthorized` | The bearer token is missing, invalid, or expired, or it isn't an Admin API token. |
| `403` | `forbidden` | The install is in read-only mode, or the token was issued on behalf of a user rather than for the credential itself. |
| `404` | `not_found` | The organization doesn't exist. |
| `409` | `conflict` | The `reference` is already used, or `owner_email` and `owner_external_id` belong to different existing users. |
| `422` | `validation_error` | `owner_email` is not a valid email address. |

The token endpoint (`/oauth/token`) returns OAuth 2.0-style errors instead, such as `{"error": "invalid_client"}`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.