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

# Authentication

> Authenticate to the TechnicallyFit API with a personal or organization API key: the header, workspaces and plans, test and live keys, scopes, rotation and revocation.

> [!NOTE]
>
> Any verified TechnicallyFit account can create API keys in a free personal developer
> workspace at [app.technicallyfit.com/developer](https://app.technicallyfit.com/developer),
> with no organization required. Organization plans unlock multi-teammate live operations
> and organization features.

The TechnicallyFit API authenticates each request with an API key that belongs to a
developer workspace: either your **personal developer workspace** or an **organization
workspace**. Both use the same key system (`tf_test_` and `tf_live_`), scopes and
`X-API-Key` header. A key says three things: which workspace is calling, in which mode
(test or live), and what the call is allowed to do (its scopes).

```bash curl theme={null}
curl "$TF_API_BASE/v1/organization" \
  -H "X-API-Key: $TF_API_KEY"
```

```typescript TypeScript theme={null}
import { createClient } from '@technicallyfit/sdk';

const tf = createClient({ credential: process.env.TF_API_KEY ?? '', baseUrl: process.env.TF_API_BASE });

const organization = await tf.GET('/v1/organization');
console.log(organization.kind, organization.plan, organization.key.scopes);
```

```python Python theme={null}
import os

from technicallyfit import Client

tf = Client(os.environ["TF_API_KEY"], base_url=os.environ.get("TF_API_BASE"))

organization = tf.get_organization()
print(organization["kind"], organization["plan"], organization["key"]["scopes"])
```

```json 200 theme={null}
{
  "id": "0b8f5c1e-6c0e-4a52-9d0a-3f3f5c2f7a11",
  "name": "Personal workspace",
  "mode": "test",
  "kind": "personal",
  "plan": "free",
  "key": {
    "id": "7e0d6a43-2b5f-4f0c-8b0f-1c1f0a9d2e55",
    "prefix": "tf_test_ab12",
    "scopes": ["teammates:read", "events:write"]
  }
}
```

```json 401 theme={null}
{
  "error": {
    "code": "unauthorized",
    "message": "A valid API key is required.",
    "request_id": "4b1d0c9e2f7a4e33a1c5d6e7f8091a2b",
    "details": {}
  }
}
```

## Send your key

Send the key in the `X-API-Key` header on every request.

```bash curl theme={null}
# example: authentication-organization
curl "$TF_API_BASE/v1/organization" \
  -H "X-API-Key: $TF_API_KEY"
```

```typescript TypeScript theme={null}
import { createClient } from '@technicallyfit/sdk';

const tf = createClient({ credential: process.env.TF_API_KEY ?? '', baseUrl: process.env.TF_API_BASE });

// An organization key (tf_test_ or tf_live_) is sent in X-API-Key.
const organization = await tf.GET('/v1/organization');
console.log(organization.mode);
```

```python Python theme={null}
import os

from technicallyfit import Client

tf = Client(os.environ["TF_API_KEY"], base_url=os.environ.get("TF_API_BASE"))

# An organization key (tf_test_ or tf_live_) is sent in X-API-Key.
organization = tf.get_organization()
print(organization["mode"])
```

`GET /v1/organization` works with any workspace key (personal or organization) and any
scope. It tells you which workspace, mode, kind and plan a key belongs to, so it is a good
first call to check a new key.

```json 200 theme={null}
{
  "id": "0b8f5c1e-6c0e-4a52-9d0a-3f3f5c2f7a11",
  "name": "Personal workspace",
  "mode": "test",
  "kind": "personal",
  "plan": "free",
  "key": {
    "id": "7e0d6a43-2b5f-4f0c-8b0f-1c1f0a9d2e55",
    "prefix": "tf_test_ab12",
    "scopes": ["teammates:read", "events:write"]
  }
}
```

| Field | Values | What it tells you |
| - | - | - |
| `kind` | `"personal"` or `"organization"` | Whether the key belongs to an individual's personal developer workspace or an organization workspace. |
| `plan` | `"free"` or `"organization"` | The API plan active on the workspace, which determines live-mode features and rate limits. |

## Personal workspaces and Organization plans

Every verified TechnicallyFit account gets a **personal developer workspace** the first
time you open [app.technicallyfit.com/developer](https://app.technicallyfit.com/developer),
with no organization required. Organizations with an active Organization plan get an
**organization workspace** for multi-teammate live operations and enterprise features.

| Capability | Personal (`plan: "free"`) | Organization (`plan: "organization"`) |
| - | - | - |
| Test mode (`tf_test_*`) | Full sandbox access (simulated teammates, test events, programs, body state, proposals and test webhooks, up to workspace caps). | Full sandbox access. |
| Live reference data (`reference:read`) | Included. | Included. |
| Live `/v1/teammates/@me` and `/v1/teammates/@me/*` | Included for the workspace owner's own data, with implicit self-consent. | Available via teammate tokens in member apps. |
| Live non-`@me` teammates (other people, placeholders, invites) | Requires Organization plan (`403 plan_required`). | Included. |
| Live webhooks, bulk events (`POST /v1/events:bulk`), locations, insights, organization settings and member-app OAuth clients | Requires Organization plan (`403 plan_required`). | Included. |
| Rate limits and workspace caps | 30 req/min, 1,000 req/day per key; workspace caps on keys, sandbox teammates, test webhooks and daily engine-heavy writes. | 100 req/min, 10,000 req/day per key; higher workspace limits. |

Calling an organization-only feature in live mode with a personal key returns `403` with
code `plan_required` and `details: { "required_plan": "organization", "feature": "..." }`.
See [Errors](https://docs.technicallyfit.com/guides/errors.md#plan-gated-errors) and
[Rate limits](https://docs.technicallyfit.com/guides/rate-limits.md#personal-workspace-caps).

To unlock organization features in live mode, use **Upgrade to an organization** in the
developer portal (`/onboarding/business`) to open the application form (an Organization
plan is set up under a contract with TechnicallyFit), or switch to an organization
workspace you administer.

## Keep API keys on a server

An API key acts for your workspace. Treat it like a password.

* Keep it in a secret manager or an environment variable on your server.
* Never put it in a mobile app, a browser, a desktop app or any other code that ships to a
  person's device. Anyone who has the app can read the key out of it.
* Never commit it to source control, and never paste it into a ticket, a chat or a log.

Your own app talks to your backend, and your backend calls TechnicallyFit with the key.

## Which credential goes where

| Where the code runs | Credential |
| - | - |
| Your servers | A personal or organization API key, in `X-API-Key`. |
| An app on a person's device | A teammate token for that one person, in `Authorization: Bearer` (requires an Organization plan). |

A teammate token comes from the person signing in to your app. It reads and changes only
that teammate's own data, and only what they allow. See [Member apps](https://docs.technicallyfit.com/guides/member-apps.md).

The same read shows the difference. `GET /v1/teammates/@me` takes either credential: with a
teammate token it answers for the person who signed in, and the SDKs send each credential in
the right header for you.

> [tab] Organization key
>
> On your server, send the organization key in `X-API-Key`. On a personal workspace,
> `@me` is you, the workspace owner.
>
> ```bash curl theme={null}
> curl "$TF_API_BASE/v1/teammates/@me" \
>   -H "X-API-Key: $TF_API_KEY"
> ```
>
> ```typescript TypeScript theme={null}
> import { createClient } from '@technicallyfit/sdk';
>
> const tf = createClient({ credential: process.env.TF_API_KEY ?? '', baseUrl: process.env.TF_API_BASE });
>
> const me = await tf.GET('/v1/teammates/@me');
> console.log(me.status, me.consent);
> ```
>
> ```python Python theme={null}
> import os
>
> from technicallyfit import Client
>
> tf = Client(os.environ["TF_API_KEY"], base_url=os.environ.get("TF_API_BASE"))
>
> me = tf.get_me()
> print(me["status"], me["consent"])
> ```

> [tab] Teammate token
>
> In an app on the person's device, send the teammate token from
> [member-app sign-in](https://docs.technicallyfit.com/guides/member-apps.md) as `Authorization: Bearer`.
>
> ```bash curl theme={null}
> curl "$TF_API_BASE/v1/teammates/@me" \
>   -H "Authorization: Bearer $TF_TEAMMATE_TOKEN"
> ```
>
> ```typescript TypeScript theme={null}
> import { createClient } from '@technicallyfit/sdk';
>
> const tf = createClient({ credential: process.env.TF_TEAMMATE_TOKEN ?? '', baseUrl: process.env.TF_API_BASE });
>
> // A teammate token (tf_at_) is sent as Authorization: Bearer.
> const me = await tf.GET('/v1/teammates/@me');
> console.log(me.external_id, me.consent.programs);
> ```
>
> ```python Python theme={null}
> import os
>
> from technicallyfit import Client
>
> tf = Client(os.environ["TF_TEAMMATE_TOKEN"], base_url=os.environ.get("TF_API_BASE"))
>
> # A teammate token (tf_at_) is sent as Authorization: Bearer.
> me = tf.get_me()
> print(me["external_id"], me["consent"]["programs"])
> ```

```json 200 theme={null}
{
  "id": "5d2b7f3e-91a4-4c6b-8e0f-2a3b4c5d6e7f",
  "external_id": "member-1042",
  "display_name": "Sam R.",
  "status": "claimed",
  "mode": "test",
  "timezone": "America/Chicago",
  "home_location_external_id": "loc-downtown",
  "consent": {
    "events": true,
    "programs": true,
    "body_state": false,
    "usage_insights": true,
    "at_risk": false,
    "program_setup": false
  },
  "account_url": "https://app.technicallyfit.com/teammate/settings#section-connected-organizations"
}
```

Both credentials reach the same API and pass the same checks, in this order. The answer at
each step that fails is the one in [When a request is refused](#when-a-request-is-refused).

```mermaid theme={null}
flowchart TD
  S["Your server"] -- "X-API-Key: tf_test_ or tf_live_ key" --> A
  D["Your app on a person's device"] -- "Authorization: Bearer teammate token" --> A
  D -. "Sign-in on a TechnicallyFit page" .-> P["The person signs in, claims or joins,<br/>and chooses what to share"]
  P -. "A teammate token for that one person" .-> D
  A["A request reaches the API"] --> V{"Credential valid and active?"}
  V -- No --> E401["401"]
  V -- Yes --> SC{"Holds the scope<br/>the call needs?"}
  SC -- No --> E403["403 forbidden"]
  SC -- Yes --> RL{"Under the rate limits?"}
  RL -- No --> E429["429 rate_limit_exceeded"]
  RL -- Yes --> PL{"Plan allows the call<br/>in this mode?"}
  PL -- No --> EPL["403 plan_required"]
  PL -- Yes --> CN{"About a claimed teammate who<br/>has not allowed the item?"}
  CN -- Yes --> ECN["403 consent_required"]
  CN -- No --> OK["Answered"]
```

## Test and live keys

Every key works in exactly one mode. The start of the key tells you which.

| Mode | Key starts with | Use it for |
| - | - | - |
| Test | `tf_test_` | Building and testing your integration in the sandbox. Test data is kept apart from live data. |
| Live | `tf_live_` | Your own live data (`/@me`) and reference data on a personal workspace, or your real organization and teammates on an Organization plan. |

A test key can never read or change live data, and a live key can never read or change
test data. Create at least one key per mode, and use a different key for each system that
calls the API so you can rotate or revoke one without touching the others.

## Scopes

A scope is one permission. A key holds one or more scopes, chosen when the key is created,
and a request succeeds only when the key holds the scope the endpoint needs. Give each key
only the scopes its system uses.

| Scope | What it unlocks |
| - | - |
| `teammates:read` | Read teammates in your workspace (or `/@me` in personal live mode). |
| `teammates:write` | Add teammates to your workspace and update them (test mode, or organization live mode). |
| `events:read` | Read back the status of training events your organization sent. |
| `events:write` | Send training events for your teammates (or `/@me` in personal live mode). |
| `programs:read` | Read your teammates' programs and their sessions. |
| `programs:write` | Set a goal and create a program for a teammate. |
| `body_state:read` | Read a teammate's body state, stored body-state changes and logged sets your organization sent. |
| `proposals:read` | Read the changes proposed for a teammate. |
| `proposals:write` | Create and answer proposed changes. |
| `webhooks:read` | Read your webhook endpoints. |
| `webhooks:write` | Create, update and delete webhook endpoints. |
| `locations:read` | Read your locations and their equipment. |
| `locations:write` | Create and update locations and their equipment. |
| `insights:read` | Read aggregate insights for your organization. |
| `reference:read` | Read reference data, such as exercises and anatomy. |
| `measurements:write` | Send measurements into a teammate's record. |
| `record:read` | Read a teammate's verified record. |
| `attestations:write` | Sign and revoke attestations for measurements you sent. |

A scope never grants more than its row says, and it only ever reaches your own workspace
in the key's mode. On a personal workspace in live mode, organization-only routes return
`403 plan_required` even if the key holds the matching scope.

An API key cannot hold a scope that edits another person's account. Teammates own their
accounts, and that does not change when they join an organization. A key also cannot hold
a wildcard that stands for every scope.

## Create, rotate and revoke keys

Sign in to TechnicallyFit at
[app.technicallyfit.com/developer](https://app.technicallyfit.com/developer) and open
**API keys**. Every verified account has a **Personal** workspace ready to use. If you are
an owner or admin of an organization, you can switch between your personal workspace and
any organization you administer. The portal also shows the base URL to call beside your
keys. Your email address must be verified before you can create or rotate a key.

Personal workspaces can hold up to **4 active API keys** at once (across test and live
modes combined). Revoke an existing key before creating another if you reach the cap.

**Create.** Choose a name, a mode and the scopes. The full key is shown once, when it is
created. Store it right away: TechnicallyFit keeps only a short prefix (such as
`tf_test_ab12`) so you can tell your keys apart, and cannot show the full key again.

**Rotate.** Rotating a key gives you a new key in the same workspace and mode with the
same scopes. You choose what happens to the old key:

* Keep it active while you deploy the new key, then revoke it. Use this for a planned
  rotation with no downtime.
* Revoke it at once. Use this when the old key may have leaked.

**Revoke.** A revoked key stops working on its next request and cannot be restored. Create
a new key if you need one.

Rotate keys on a schedule, and rotate at once when someone who could see a key leaves your
team or a key may have been exposed.

## When a request is refused

| Status | What it means | What to do |
| - | - | - |
| `401` | The key is missing, is not a valid key, has been revoked, or belongs to a workspace that is not active. | Check that the `X-API-Key` header is set and that the key has not been revoked. |
| `403` | The key is valid but is not allowed to make this call: it lacks the required scope (`forbidden`), uses the wrong mode, or calls an organization-only live feature on a personal workspace (`plan_required`). | Check `GET /v1/organization` for your scopes, mode and plan. Create a key with the scope you need, switch to a test key for sandbox calls, or apply for an Organization plan (set up under a contract with TechnicallyFit) via the developer portal. |
| `409` | A personal workspace cap was reached, such as attempting to create more than 4 active keys (`personal_api_key_limit_reached`). | Revoke an unused key, or apply for an Organization plan via the developer portal. |
| `422` | A key was requested with a scope that an API key cannot hold, or with no scopes. | Use only the scopes in the table above. The response names each scope that was refused. |

A key without the scope an endpoint needs is answered like this, here for
`GET /v1/teammates` with a key that holds only `reference:read`:

```bash curl theme={null}
curl "$TF_API_BASE/v1/teammates" \
  -H "X-API-Key: $TF_API_KEY"
```

```json 403 theme={null}
{
  "error": {
    "code": "forbidden",
    "message": "This API key is not allowed to make this call.",
    "request_id": "c0ffee12ab3448d9b1e2f3a4b5c6d7e8",
    "details": { "required_scope": "teammates:read" }
  }
}
```

Every error from the API has the same body, with a stable code and a request ID. See
[Errors](https://docs.technicallyfit.com/guides/errors.md) for the full list.


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