# Authentication & credentials

Canonical URL: https://docs.chartvoyant.com/authentication/

ChartVoyant never shares one catch-all credential across unrelated trust boundaries. Each surface uses a purpose-built token bound to a single practice (and, where applicable, a single patient or HL7 interface).

## Credential comparison matrix

| Credential | Prefix / Type | Accepted On | Lifetime | How Issued |
| --- | --- | --- | --- | --- |
| **Practice API key** | `Bearer cvk_…` | [REST API](https://docs.chartvoyant.com/rest-api/), [Practice MCP](https://docs.chartvoyant.com/mcp/), REST C-CDA | 14d (sandbox) · 90d default / 365d max (prod) | Self-serve sandbox modal, or ChartVoyant onboarding |
| **Patient MCP key** | `Bearer cvpk_…` or URL segment | [Patient MCP](https://docs.chartvoyant.com/patient-mcp/) only | 30, 90, 180, or 365 days | Created by the patient in Portal → Account → AI assistants or `/mcp-self-register/` |
| **HL7 sender key** | `Bearer cvk_…` (ingest-only) | One bound [HL7 v2 interface](https://docs.chartvoyant.com/hl7/) | Per interface term | Issued during HL7 interface setup |
| **SMART user/patient token** | Opaque OAuth 2 Bearer | [FHIR R4](https://docs.chartvoyant.com/fhir-r4/), [SMART Write](https://docs.chartvoyant.com/smart-write/) | 3,600s read (300s with write scope); 95d offline refresh | `auth.chartvoyant.com` Authorization Code + PKCE `S256` |
| **SMART backend token** | Opaque OAuth 2 Bearer | [FHIR R4](https://docs.chartvoyant.com/fhir-r4/), [Bulk Data](https://docs.chartvoyant.com/bulk-data/), [HL7](https://docs.chartvoyant.com/hl7/) (with `system/hl7v2-ingest`) | 3,600s read (300s write); no refresh token | `client_credentials` + `private_key_jwt` (`RS384` or `ES384`) |

## Practice API keys (`cvk_`)

    cvkMarker
    _a1b2c3d4e5f612-hex prefix
    _Xk9…QzSecret

Send the key on every request as `Authorization: Bearer cvk_…` over HTTPS. Every key resolves to a single tenant — there is no header or query parameter that switches practices. Keys carry either `read_only` (safe HTTP methods + read-only MCP tools) or `full` (reads + permitted writes).

## Patient MCP keys (`cvpk_`)

    cvpkMarker
    _3e91c0a7d2b412-hex prefix
    _Xk9…Qz43-char secret

Created exclusively by the patient after re-entering their portal password. Accepted only on `POST https://chartvoyant.com/api/v1/portal/mcp` (via `Authorization: Bearer`) or `POST https://chartvoyant.com/api/v1/portal/mcp/{key}` for URL-only connectors. Always read-only and scoped to that single patient's portal-visible chart.

## SMART App Launch OAuth 2 & PKCE

Interactive patient, clinician, and EHR launches discover endpoints from `https://fhir.chartvoyant.com/r4/{practice}/.well-known/smart-configuration`. Every authorization code flow requires:

- `code_challenge_method=S256` (plain or missing PKCE is rejected)

- `aud` matching the exact FHIR base URL from the [Practice Endpoint Directory](https://docs.chartvoyant.com/endpoint-directory/)

- Exact registered `redirect_uri` (HTTPS, or `localhost` / `127.0.0.1` loopback for native apps)

See [SMART App Launch 2](https://docs.chartvoyant.com/smart-app-launch/) and the [SMART on FHIR-4 developer guide](https://docs.chartvoyant.com/fhir/#launch) for complete browser PKCE code.

## SMART Backend Services (`private_key_jwt`)

Headless system integrations authenticate to `POST https://auth.chartvoyant.com/oauth/token` using `grant_type=client_credentials` and `client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer` signed with `RS384` or `ES384` against your registered public JWKS. Assertions expire within 5 minutes and require a unique `jti`. See [SMART Backend Services](https://docs.chartvoyant.com/smart-backend-services/).

## HL7 v2 interface credentials

Each [HL7 v2 interface](https://docs.chartvoyant.com/hl7/) accepts only the single credential bound to its `interfaceId`: either a dedicated HL7 sender key (`Bearer cvk_…` with ingest-only permission) or a SMART Backend Services token carrying `scope=system/hl7v2-ingest`. Ordinary REST API keys and sandbox keys are rejected with `401`.

## Credential security rules

- **TLS 1.2+ everywhere.** Plain HTTP is never served on any ChartVoyant host.

- **Quote prefixes, never secrets.** When contacting support, share only the 12-character key prefix (for example `a1b2c3d4e5f6`) and `correlationId`.

- **Keep keys out of client bundles and chat transcripts.** Never ship a `cvk_` key in browser JS, mobile binaries, git repositories, CI logs, or AI chat prompts.

- **Immediate rotation & revocation.** Report any suspected leak to [info@chartvoyant.com](mailto:info@chartvoyant.com?subject=URGENT%3A%20possible%20API%20key%20exposure) within 24 hours; revocation takes effect on the next request.
