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

# Manage your account with the Cloud Platform API

> Sign in from a script, then manage organizations, workspaces, API keys, members, usage and billing through https://cloud-platform.near.ai.

The Cloud Platform API lets you do from a script or a coding agent what you do in the NEAR AI Cloud console: create organizations and workspaces, issue API keys, invite members and read usage and spend. Inference (chat completions, responses, images and the like) stays on `https://cloud-api.near.ai`.

All examples use `https://cloud-platform.near.ai`. Ids such as `ORG_ID` are UUIDs returned by earlier calls.

## Credentials

Calls that need a credential send `Authorization: Bearer <credential>`. Which credential a call takes depends on the call:

| Credential | Looks like | Where it comes from | Used for |
| - | - | - | - |
| Session access token | a long token, no prefix | Signing in, or refreshing | Almost every call in this guide |
| Refresh token | `rt_...` | Signing in | Getting a new access token, signing out |
| API key | `sk-...` | [Create an API key](#api-keys) | `POST /v1/billing/costs`, and inference on cloud-api |
| Reporting token | `rpt-...` | [Reporting tokens](#reporting-tokens) | Read-only usage reporting |

Tokens issued by cloud-api are not accepted by cloud-platform. Sign in against cloud-platform as shown below. Unless a section says otherwise, the examples use `$ACCESS_TOKEN`.

## Sign in from a script or agent

### GitHub or Google

1. Open `https://cloud-platform.near.ai/v1/auth/github` (or `/v1/auth/google`) in a browser. It redirects to the provider.
2. After you approve, the provider sends the browser to `/v1/auth/callback`, which answers with JSON:

```json theme={"dark"}
{
  "access_token": "eyJ...",
  "refresh_token": "rt_...",
  "refresh_token_expiration": "2026-12-10T12:00:00Z",
  "user": { "message": "...", "email": "you@example.com", "provider": "github" }
}
```

3. Copy `access_token` and `refresh_token` into your environment:

```bash theme={"dark"}
export ACCESS_TOKEN="eyJ..."
export REFRESH_TOKEN="rt_..."
```

After the browser step, refresh from the script until the refresh token expires; then sign in again.

### NEAR wallet

Sign a NEP-413 message with your wallet, then post the signature and the payload that was signed:

```bash theme={"dark"}
curl -X POST https://cloud-platform.near.ai/v1/auth/near \
  -H "Content-Type: application/json" \
  -d '{
    "signed_message": {
      "accountId": "alice.near",
      "publicKey": "ed25519:...",
      "signature": "BASE64_SIGNATURE"
    },
    "payload": {
      "message": "THE_SIGNED_MESSAGE",
      "nonce": [0, 1, 2, "...32 integers in total"],
      "recipient": "THE_RECIPIENT"
    }
  }'
```

The response has the same shape as the callback above.

### Refresh the access token

When the access token stops working (HTTP 401), exchange the refresh token for a new one:

```bash theme={"dark"}
curl -X POST https://cloud-platform.near.ai/v1/users/me/access-tokens \
  -H "Authorization: Bearer $REFRESH_TOKEN"
```

```json theme={"dark"}
{
  "access_token": "eyJ...",
  "refresh_token": "rt_...",
  "refresh_token_expiration": "2026-12-17T12:00:00Z"
}
```

> [!WARNING]
>
> Every refresh returns a **new** refresh token and replaces the one you sent. Store the new `refresh_token` each time. The next refresh must use it.

### Sign out and revoke

```bash theme={"dark"}
# End the session of this refresh token (access tokens issued for it stop working)
curl -X POST https://cloud-platform.near.ai/v1/auth/logout \
  -H "Authorization: Bearer $REFRESH_TOKEN"

# Revoke the credential you are calling with (any credential kind)
curl -X POST https://cloud-platform.near.ai/v1/auth/revoke \
  -H "Authorization: Bearer $NEAR_AI_API_KEY"
```

Revoking `NEAR_AI_API_KEY` as above deletes that key, so only run it when you want the key gone. `/v1/auth/revoke` revokes only the credential in the header and answers with its kind and id. To manage your signed-in sessions:

```bash theme={"dark"}
# List your refresh tokens (ids, creation and expiry times; never the token values)
curl https://cloud-platform.near.ai/v1/users/me/refresh-tokens \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Revoke one session
curl -X DELETE https://cloud-platform.near.ai/v1/users/me/refresh-tokens/$REFRESH_TOKEN_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Revoke all of them
curl -X DELETE https://cloud-platform.near.ai/v1/users/me/tokens \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

## Your account

```bash theme={"dark"}
curl https://cloud-platform.near.ai/v1/users/me \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Returns your profile (`id`, `email`, `username`, `display_name`, `avatar_url`, `auth_provider`) and the organizations and workspaces you belong to, each organization with your `role`. Use it to find the ids for the calls below.

`GET /v1/users/me/status` checks that the account is in good standing. `PUT /v1/users/me/profile` with `display_name` and `avatar_url` updates your profile.

## Organizations and workspaces

An organization owns the balance and the members. Workspaces inside it own API keys.

```bash theme={"dark"}
# Create an organization
curl -X POST https://cloud-platform.near.ai/v1/organizations \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "Acme AI", "description": "Production workloads"}'

# List your organizations (limit 1-1000, offset, order_by=created_at|joined_at, order_direction=asc|desc)
curl "https://cloud-platform.near.ai/v1/organizations?limit=20" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Create a workspace
curl -X POST https://cloud-platform.near.ai/v1/organizations/$ORG_ID/workspaces \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "backend", "description": "Backend services"}'

# List workspaces
curl https://cloud-platform.near.ai/v1/organizations/$ORG_ID/workspaces \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Names are 1 to 255 characters. A workspace name is unique within its organization.

Rename or re-describe with `PUT /v1/organizations/{org_id}` or `PUT /v1/workspaces/{workspace_id}` (send only the fields to change). `DELETE` on the same paths deletes them. Read one with `GET /v1/organizations/{org_id}` or `GET /v1/workspaces/{workspace_id}`.

### Organization settings

```bash theme={"dark"}
curl https://cloud-platform.near.ai/v1/organizations/$ORG_ID/settings \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Change settings with `PATCH`. For each field, leaving it out changes nothing and `null` restores the default. Only owners and admins can change model restrictions.

```bash theme={"dark"}
curl -X PATCH https://cloud-platform.near.ai/v1/organizations/$ORG_ID/settings \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "fallback_enabled": true,
    "allowed_models": ["MODEL_NAME"],
    "long_context_disabled_models": []
  }'
```

| Field | Effect |
| - | - |
| `fallback_enabled` | Whether requests may use providers configured as fallbacks. |
| `allowed_models` | The only models the organization's API keys may use. `null` allows every model. An empty list is rejected. |
| `long_context_disabled_models` | Models whose long-context tier is turned off. `null` or an empty list turns it on for every model. |

The response also lists each model's long-context state under `long_context` (read-only).

## API keys

API keys belong to a workspace. They authenticate inference requests on `https://cloud-api.near.ai`.

```bash theme={"dark"}
# Create a key (spendLimit is optional; amount is in nano-dollars, so 50000000000 = $50)
curl -X POST https://cloud-platform.near.ai/v1/workspaces/$WORKSPACE_ID/api-keys \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "ci",
    "expires_at": "2027-01-01T00:00:00Z",
    "spendLimit": { "amount": 50000000000, "currency": "USD" }
  }'
```

The response contains the full secret in `key` (it begins with `sk-`). **It is shown only in this response and cannot be retrieved again.** Store it right away.

```bash theme={"dark"}
export NEAR_AI_API_KEY="sk-..."
```

```bash theme={"dark"}
# List keys (secrets are never returned; order_by=created_at|usage)
curl "https://cloud-platform.near.ai/v1/workspaces/$WORKSPACE_ID/api-keys?limit=50" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Rename, change expiry, disable (is_active=false) or enable a key
curl -X PATCH https://cloud-platform.near.ai/v1/workspaces/$WORKSPACE_ID/api-keys/$KEY_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "ci-renamed", "is_active": false}'

# Set the spend limit; null removes it
curl -X PATCH https://cloud-platform.near.ai/v1/workspaces/$WORKSPACE_ID/api-keys/$KEY_ID/spend-limit \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"spendLimit": {"amount": 100000000000, "currency": "USD"}}'

# Revoke a key
curl -X DELETE https://cloud-platform.near.ai/v1/workspaces/$WORKSPACE_ID/api-keys/$KEY_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

## Members and invitations

Roles are `owner`, `admin` and `member`.

```bash theme={"dark"}
# Invite by email (1 to 100 invitations per call)
curl -X POST https://cloud-platform.near.ai/v1/organizations/$ORG_ID/members/invite-by-email \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"invitations": [{"email": "teammate@example.com", "role": "member"}]}'
```

The response has one entry per invitation in `results`, with `success`, `email_sent` and, if it failed, an `error`.

```bash theme={"dark"}
# List members
curl "https://cloud-platform.near.ai/v1/organizations/$ORG_ID/members?limit=100" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# List invitations (optional status=pending|accepted|declined|expired)
curl "https://cloud-platform.near.ai/v1/organizations/$ORG_ID/members/invitations?status=pending" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Cancel an invitation
curl -X DELETE https://cloud-platform.near.ai/v1/organizations/$ORG_ID/members/invitations/$INVITATION_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Change a member's role
curl -X PUT https://cloud-platform.near.ai/v1/organizations/$ORG_ID/members/$USER_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"role": "admin"}'

# Remove a member
curl -X DELETE https://cloud-platform.near.ai/v1/organizations/$ORG_ID/members/$USER_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

### Accept an invitation

The invited user signs in and then either lists their pending invitations and accepts one by id:

```bash theme={"dark"}
curl https://cloud-platform.near.ai/v1/users/me/invitations \
  -H "Authorization: Bearer $ACCESS_TOKEN"

curl -X POST https://cloud-platform.near.ai/v1/users/me/invitations/$INVITATION_ID/accept \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

or accepts with the token from the invitation email:

```bash theme={"dark"}
curl -X POST https://cloud-platform.near.ai/v1/invitations/$INVITATION_TOKEN/accept \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Decline with `POST /v1/users/me/invitations/{invitation_id}/decline`.

## Usage and billing

Reads take the session access token. Dates are ISO 8601; ranges may not exceed 366 days.

```bash theme={"dark"}
# Balance
curl https://cloud-platform.near.ai/v1/organizations/$ORG_ID/usage/balance \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Per-request history (limit 1-1000, offset, start_date, end_date, workspace_id, api_key_id, credit_type)
curl "https://cloud-platform.near.ai/v1/organizations/$ORG_ID/usage/history?limit=100&start_date=2026-12-01" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Usage per model (period=day|week|month|custom, or start/end)
curl "https://cloud-platform.near.ai/v1/organizations/$ORG_ID/usage/by-model?period=week" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Totals and breakdowns for a range
curl "https://cloud-platform.near.ai/v1/organizations/$ORG_ID/usage/metrics?start=2026-12-01T00:00:00Z" \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Time series (granularity=hour|day|week)
curl "https://cloud-platform.near.ai/v1/organizations/$ORG_ID/usage/timeseries?granularity=day" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Amounts named `total_cost` and `total_spent` are in nano-dollars (10^-9 USD); `*_display` fields are human readable. History for a single key is at `GET /v1/workspaces/{workspace_id}/api-keys/{api_key_id}/usage/history`.

### Cost of individual requests

Each history entry has an `inference_id`. Inference responses also carry it in the `inference-id` header. Send up to 10,000 of these ids with an **API key** (not an access token) to get their costs:

```bash theme={"dark"}
curl -X POST https://cloud-platform.near.ai/v1/billing/costs \
  -H "Authorization: Bearer $NEAR_AI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"requestIds": ["44444444-4444-4444-8444-444444444444"]}'
```

```json theme={"dark"}
{
  "requests": [
    { "requestId": "44444444-4444-4444-8444-444444444444", "costNanoUsd": 1230000 }
  ]
}
```

Ids with no usage record come back with a cost of 0 and a `warning`. Usage can take a few seconds to appear after a request finishes. This call is served by `https://cloud-platform.near.ai`; the copy on `https://cloud-api.near.ai` will be removed on 2026-12-07, together with the usage balance endpoint. See the [migration guide](https://docs.near.ai/cloud/guides/cloud-platform-migration.md).

### Reporting tokens

A reporting token (`rpt-...`) is a read-only credential for usage reporting, separate from API keys. Owners and admins manage them with an access token:

```bash theme={"dark"}
# Create (expires_at is optional)
curl -X POST https://cloud-platform.near.ai/v1/organizations/$ORG_ID/reporting-tokens \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"name": "finance", "expires_at": "2026-12-31T23:59:59Z"}'

# List (prefixes and timestamps only)
curl https://cloud-platform.near.ai/v1/organizations/$ORG_ID/reporting-tokens \
  -H "Authorization: Bearer $ACCESS_TOKEN"

# Revoke
curl -X DELETE https://cloud-platform.near.ai/v1/organizations/$ORG_ID/reporting-tokens/$TOKEN_ID \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

The `token` value is shown only in the create response. See the [Usage Reporting API](https://docs.near.ai/cloud/guides/usage-reporting.md) for how reporting tokens are used.

## Next steps

* The [Cloud Platform API reference](https://docs.near.ai/api-reference/cloud-platform/introduction.md) lists every request and response field.
* Moving existing scripts from cloud-api? See [Cloud Platform migration](https://docs.near.ai/cloud/guides/cloud-platform-migration.md).


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