> ## 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.

# Adapting a source

> Map any source's records (a device, a partner system, a file, your own app) into observations and logged sets, and prove the mapping with the conformance kit before it reaches a teammate's data.

Every source enters TechnicallyFit the same way. A source adapter turns one record of your
source into the [events](https://docs.technicallyfit.com/guides/sending-events.md) the API already takes: `observation`
events in the `observation/1` format (see [Observations](https://docs.technicallyfit.com/guides/observations.md)) and
`logged_set` events. Nothing else changes: the events go to
`POST /v1/teammates/{external_id}/events` like any other, with the same consent, test and
live modes, route limits and duplicate handling.

An adapter is a mapping, not a connection. It does not call your source, store tokens or
poll anything; moving the records is yours (or the SDK's). It also builds toward no one
provider: the contract, the kit and the examples here name no device or vendor.

## The manifest

Each adapter declares what it maps in a manifest, `source-adapter/2` (`source-adapter/1`
remains supported for existing adapters). The JSON Schema ships in
`@technicallyfit/source-adapters` on npm as `manifest.schema.json`.

```json theme={null}
{
  "schema": "source-adapter/2",
  "name": "org-readings",
  "version": "1.0.0",
  "route": "org-readings",
  "description": "A morning summary and heart rate stream from sensors the organization runs.",
  "requested_limits": { "may_store": true, "vera_may_read": false },
  "device": { "kind": "heart_rate_chest_strap", "instrument": null },
  "record_types": [
    {
      "type": "morning_summary",
      "emits": "observation",
      "timing": { "streaming": false, "expected_delay_ms": 5000 },
      "produces": [
        { "quantity": "resting_heart_rate", "measure": null, "unit": "bpm", "body": "none", "default_confidence": 0.8 },
        { "quantity": "heart_rate_variability", "measure": "rmssd", "unit": "ms", "body": "none", "default_confidence": 0.8 },
        { "quantity": "readiness_score", "measure": null, "unit": "score", "body": "none", "default_confidence": 0.6 }
      ]
    },
    {
      "type": "heart_rate_measurement",
      "emits": "observation",
      "timing": { "streaming": true, "sample_rate_hz": 1, "expected_delay_ms": 250 },
      "reducers": [
        { "id": "set_heart_rate_mean", "version": 1 },
        { "id": "set_heart_rate_peak", "version": 1 }
      ],
      "produces": [
        { "quantity": "heart_rate", "measure": "mean", "unit": "bpm", "body": "none", "default_confidence": 0.9 },
        { "quantity": "heart_rate", "measure": "peak", "unit": "bpm", "body": "none", "default_confidence": 0.9 }
      ]
    },
    { "type": "gym_set", "emits": "logged_set", "default_confidence": 0.9 }
  ]
}
```

| Field | What it means |
| - | - |
| `schema` | `source-adapter/2` (recommended) or `source-adapter/1`. |
| `name`, `version` | The adapter and its mapping version (`MAJOR.MINOR.PATCH`). Change the version whenever a mapping changes. |
| `route` | The route id every event names in `source.route`. A record type may name a TechnicallyFit route instead (`teammate` or `coach`, for self-reports). |
| `requested_limits` | What the adapter asks for. It is a request: the route's own limits, which only TechnicallyFit sets, always win. See [Data use](https://docs.technicallyfit.com/guides/data-use.md). |
| `device` | (`source-adapter/2`) Neutral device identity: `kind` (a lower-case device kind token such as `heart_rate_chest_strap` or `smart_scale`, never a maker) and optional `instrument`. |
| `record_types[].emits` | `observation` or `logged_set`. |
| `record_types[].timing` | (`source-adapter/2`) Whether the record type is `streaming` (high-rate samples reduced before ingestion) or discrete, plus optional `sample_rate_hz` and `expected_delay_ms`. |
| `record_types[].reducers` | (`source-adapter/2`, streaming record types) References (`id` and `version`) to declared stream reducers, which turn samples into summaries such as a mean or a peak. |
| `produces[]` | Per quantity: the measure, the unit, where on the body (`none`, `from_record`, or a fixed joint and side) and the most the reading is trusted (`default_confidence`). |
| `produces[].unregistered` | `true` only for a quantity the registry does not list yet (see below). |

## The rules

* **Registry quantities only.** Map each reading to a quantity in the
  [quantity registry](https://docs.technicallyfit.com/guides/observations.md), in a unit the registry converts. Do not invent a
  name or a unit for something the registry already has.
* **Unlisted quantities are declared, not hidden.** A reading the registry does not list yet
  may be sent with its own lower-case name if the manifest marks it `unregistered`. The API
  stores it as `not_interpreted` (its kind is `unknown`), and when the registry later gains
  the quantity, stored readings inside the replay window are offered to the engine once.
* **Scores stay scores.** A score your source computes (readiness, recovery, stress) is sent
  as the registry's score quantity for it. It is carried and never acted on; do not map it to
  a measured quantity.
* **Summaries only.** One observation is one number: never a list of samples or a stream.
  `context` stays under 2 KB and holds only text, numbers, `true`, `false` or `null`.
* **Unlike measures stay apart.** A quantity with several measures (two kinds of heart rate
  variability, mean and peak bar speed) is sent once per measure, each with its `measure`.
  Two measures are never averaged into one observation.
* **Stable record ids.** `source.record_id` is your source's own id for the record, the same
  on every run, so a retry or a resend is answered `duplicate`. Two readings of one record
  get their own ids (for example the record id plus `#` and the quantity).
* **No more trust than declared.** An event's `confidence` is at most the record type's
  `default_confidence`. The route's own default caps it again when it is stored.
* **No vouching field.** An adapter never sets `vouching` on an observation; TechnicallyFit
  assigns vouching at ingestion time.
* **Declared reducers for streams.** A streaming record type reduces its samples into
  summaries (such as a mean, a peak, or time in a zone) using declared stream reducers
  before sending observations to the API. See [Supported devices](https://docs.technicallyfit.com/reference/supported-devices.md)
  for the built-in starter adapters.
* **Provenance.** Every observation names its adapter in `context.adapter` as
  `name/version`, so a later correction can tell which mapping produced it.
* **No teammate inside.** An adapter's events leave `teammate` out; the request path names
  the teammate.
* **Neutral names.** Names, routes, record ids and device labels describe what the data is,
  never whose product made it.

## Running the kit

Install the conformance kit from npm (`npm install @technicallyfit/source-adapters`), then
give `runConformance` your adapter and a sample record for every record type:

```ts theme={null}
import { runConformance } from '@technicallyfit/source-adapters';

const report = await runConformance(adapter, [
  { type: 'morning_summary', record: { id: 'm1', at: '2026-11-17T06:30:00Z', restingBpm: 52, rmssdMs: 61, readiness: 74 } },
  { type: 'gym_set', record: { id: 's1', at: '2026-11-17T18:00:00Z', number: 1 } },
]);
console.log(report.passed, report.checks);
```

Each check has a stable id:

| Check | Fails when |
| - | - |
| `manifest.valid` | The manifest does not match `source-adapter/1` or `source-adapter/2`, or a record type has no sample. |
| `events.schema` | An event does not validate against `observation/1` or the logged-set format, or sets `vouching`. |
| `events.registry` | A quantity is not in the registry and not declared `unregistered`, or its unit or measure is not one the registry takes. |
| `events.body` | A joint or side is not valid, or the body does not match the manifest. |
| `events.confidence` | A confidence is above the declared default. |
| `events.summary_only` | A value is a list or a stream, `context` is too large, or one record yields two readings of the same quantity, measure and body. |
| `events.measures_apart` | A quantity with several measures is sent without one. |
| `events.provenance` | An observation does not name its adapter and version. |
| `record_id.stable` | Two runs over the same samples give different events or record ids, or two records share an id. |
| `neutral.names` | The manifest, a route, a record id or a device names a listed vendor. |
| `live.accepted_then_duplicate` | (Live step only) the first send is not all `accepted` or the second not all `duplicate`. |

A report's details name the sample, the event and the field; they never quote a value.

### The live step

Pass a test key and a test-mode teammate to send the samples to the API twice:

```ts theme={null}
const report = await runConformance(adapter, samples, {
  baseUrl: process.env.TF_API_BASE ?? '',
  apiKey: process.env.TF_API_KEY ?? '',
  teammate: 'kit-teammate-1',
});
```

It passes only when the first send is all `accepted` and the second all `duplicate`. The kit
refuses a live key, so a conformance run never writes to a real teammate's history. Use a
fresh test teammate (or the [sandbox](https://docs.technicallyfit.com/guides/sandbox.md)) for each run, since a second run on
the same teammate is all `duplicate` from the start.

## Sending the mapped events

Once the kit passes, your own code moves the records: read a record from your source, map it
with the adapter, and send the events it returns for the teammate the record belongs to.

**1. Map one record**

Call `toEvents` on your adapter with one record of your source. The `morning_summary`
sample above becomes one observation per reading, each with its own record id and the
adapter named in `context.adapter`. An adapter leaves `teammate` out of each event.

**2. Send the events for the teammate**

Send them to `POST /v1/teammates/{external_id}/events` with your organization key, which
needs `events:write`. The request on this page sends the first two readings of the
sample for `member-1042`.

**3. Read the results**

Each event gets its own result. A first send answers `accepted`; sending the same record
again answers `duplicate`, because the record ids are stable.

```bash curl theme={null}
curl -X POST "$TF_API_BASE/v1/teammates/member-1042/events" \
  -H "X-API-Key: $TF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "events": [
    {
      "type": "observation",
      "data": {
        "schema": "observation/1",
        "quantity": "resting_heart_rate",
        "measure": null,
        "value": 52,
        "unit": "bpm",
        "at": "2026-11-17T06:30:00Z",
        "source": { "route": "org-readings", "device": "wrist-sensor", "record_id": "m1#resting_heart_rate" },
        "confidence": 0.8,
        "context": { "adapter": "org-readings/1.0.0" }
      }
    },
    {
      "type": "observation",
      "data": {
        "schema": "observation/1",
        "quantity": "heart_rate_variability",
        "measure": "rmssd",
        "value": 61,
        "unit": "ms",
        "at": "2026-11-17T06:30:00Z",
        "source": { "route": "org-readings", "device": "wrist-sensor", "record_id": "m1#heart_rate_variability#rmssd" },
        "confidence": 0.8,
        "context": { "adapter": "org-readings/1.0.0" }
      }
    }
  ]
}'
```

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

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

// The events your adapter returned for one morning_summary record.
const events = [
  {
    type: 'observation',
    data: {
      schema: 'observation/1',
      quantity: 'resting_heart_rate',
      measure: null,
      value: 52,
      unit: 'bpm',
      at: '2026-11-17T06:30:00Z',
      source: {
        route: 'org-readings',
        device: 'wrist-sensor',
        record_id: 'm1#resting_heart_rate'
      },
      confidence: 0.8,
      context: {
        adapter: 'org-readings/1.0.0'
      }
    }
  },
  {
    type: 'observation',
    data: {
      schema: 'observation/1',
      quantity: 'heart_rate_variability',
      measure: 'rmssd',
      value: 61,
      unit: 'ms',
      at: '2026-11-17T06:30:00Z',
      source: {
        route: 'org-readings',
        device: 'wrist-sensor',
        record_id: 'm1#heart_rate_variability#rmssd'
      },
      confidence: 0.8,
      context: {
        adapter: 'org-readings/1.0.0'
      }
    }
  }
] as const;

const answer = await tf.POST('/v1/teammates/{external_id}/events', {
  params: { path: { external_id: 'member-1042' } },
  body: { events: [...events] },
});
console.log(answer.summary);
```

```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"))

# The events your adapter returned for one morning_summary record.
events = [
    {
        "type": "observation",
        "data": {
            "schema": "observation/1",
            "quantity": "resting_heart_rate",
            "measure": None,
            "value": 52,
            "unit": "bpm",
            "at": "2026-11-17T06:30:00Z",
            "source": {
                "route": "org-readings",
                "device": "wrist-sensor",
                "record_id": "m1#resting_heart_rate"
            },
            "confidence": 0.8,
            "context": {
                "adapter": "org-readings/1.0.0"
            }
        }
    },
    {
        "type": "observation",
        "data": {
            "schema": "observation/1",
            "quantity": "heart_rate_variability",
            "measure": "rmssd",
            "value": 61,
            "unit": "ms",
            "at": "2026-11-17T06:30:00Z",
            "source": {
                "route": "org-readings",
                "device": "wrist-sensor",
                "record_id": "m1#heart_rate_variability#rmssd"
            },
            "confidence": 0.8,
            "context": {
                "adapter": "org-readings/1.0.0"
            }
        }
    }
]

answer = tf.send_teammate_events("member-1042", {"events": events})
print(answer["summary"])
```

```json 200 theme={null}
{
  "results": [
    {
      "index": 0,
      "status": "accepted",
      "type": "observation",
      "event_id": "6f1c2b9e-3d4a-4e8b-9c7f-1a2b3c4d5e60",
      "observation": {
        "kind": "whole_body",
        "status": "not_interpreted"
      }
    },
    {
      "index": 1,
      "status": "accepted",
      "type": "observation",
      "event_id": "7a2d3c0f-4e5b-4f9c-8d1a-2b3c4d5e6f71",
      "observation": {
        "kind": "whole_body",
        "status": "not_interpreted"
      }
    }
  ],
  "summary": {
    "accepted": 2,
    "duplicate": 0,
    "rejected": 0
  }
}
```

## Worked example: the TechnicallyFit app

TechnicallyFit's own app is the reference adapter. It proves the path
[without a device](https://docs.technicallyfit.com/guides/without-a-device.md): sets the teammate logged, and pain reports.

```json theme={null}
{
  "schema": "source-adapter/1",
  "name": "technicallyfit-app",
  "version": "1.0.0",
  "route": "app",
  "description": "TechnicallyFit app: sets the teammate logged, and pain reports.",
  "requested_limits": { "may_store": true, "vera_may_read": true },
  "record_types": [
    { "type": "set", "emits": "logged_set", "default_confidence": 1.0 },
    { "type": "pain_report", "emits": "observation", "route": "teammate",
      "produces": [{ "quantity": "pain", "measure": null, "unit": "score_0_10", "body": "from_record", "default_confidence": 1.0 }] },
    { "type": "pain_report_by_coach", "emits": "observation", "route": "coach",
      "produces": [{ "quantity": "pain", "measure": null, "unit": "score_0_10", "body": "from_record", "default_confidence": 0.9 }] }
  ]
}
```

| App record | Event | Mapping |
| - | - | - |
| A logged set | `logged_set` on route `app` | `record_id` is `app:set:{id}`; the movement by catalog id, else by name; `effort` only when the app stored one number. Session markers and voided sets map to nothing. |
| A pain report by the teammate | `observation`, quantity `pain`, route `teammate` | The joint and side from the report (a midline joint's side is `midline`); the severity on the 0 to 10 scale; `context.timing`; `record_id` is `app:pain:{id}`. |
| A pain report a coach logged | The same, on route `coach` | The coach is not named in the event. |

A pain report becomes:

```json theme={null}
{
  "type": "observation",
  "data": {
    "schema": "observation/1",
    "quantity": "pain",
    "measure": null,
    "value": 4,
    "unit": "score_0_10",
    "at": "2026-11-17T18:05:00.5Z",
    "until": null,
    "body": { "joint": "knee", "side": "left" },
    "source": { "route": "teammate", "device": null, "record_id": "app:pain:0b6e2f4a-2222-4c2d-9a3e-000000000001" },
    "confidence": 1,
    "context": { "timing": "during_set", "adapter": "technicallyfit-app/1.0.0" }
  }
}
```

Soreness is not mapped in this version: the app records it per muscle, and observations
are per joint.


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