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

# Native vs. Anthropic-Compat

> When to use the native HASP AI surface (/v1/ai/*) versus the Anthropic-compatible surface (/v1/messages).

The HASP AI API exposes three inference surfaces: the native surface, the Anthropic-compatible surface, and the [OpenAI-compatible surface](/ai-api/reference/chat-completions). All three enforce the same compliance checks — BAA validation, credit accounting, PHI scanning — and all three reach the same Anthropic **and** OpenAI models; they differ only in wire format and who they're designed for. This page compares the two most common choices: native versus Anthropic-compat. If you already build against the `openai` SDK, see the [OpenAI-compat reference](/ai-api/reference/chat-completions) instead.

## Surface comparison

|                       | Native (`/v1/ai/chat`)                           | Anthropic-compat (`/v1/messages`)                    |
| --------------------- | ------------------------------------------------ | ---------------------------------------------------- |
| **Primary use case**  | New integrations, regulated workflows            | Drop-in for existing Anthropic SDK code              |
| **Migration effort**  | Minimal (HASP-native SDK)                        | None — change `baseURL` only                         |
| **Response envelope** | HASP envelope with `meta.request_id`, `meta.phi` | Anthropic wire format                                |
| **Error format**      | HASP error codes (`INVALID_API_KEY`, etc.)       | Anthropic error types (`authentication_error`, etc.) |
| **Streaming**         | SSE with HASP event taxonomy                     | SSE matching Anthropic's stream protocol             |
| **PHI metadata**      | Exposed in response (`meta.phi.*`)               | Not exposed                                          |
| **Audit access**      | Retrieve via `GET /v1/ai/messages/{id}`          | Same — `request_id` maps to same record              |
| **Future features**   | First to get HASP-native capabilities            | Anthropic wire compatibility only                    |

## When to use native (`/v1/ai/chat`)

Use the native surface when you:

* Are building a new integration and want full HASP capabilities from the start.
* Need PHI metadata in responses (entity types detected, redaction count).
* Want the HASP error vocabulary (`PHI_BLOCKED`, `BAA_REQUIRED`, etc.) rather than the Anthropic mapping.
* Are building tooling against the audit trail and want the richest response envelope.

## When to use Anthropic-compat (`/v1/messages`)

Use the compat surface when you:

* Already have code using `@anthropic-ai/sdk` and want HASP compliance with zero code changes.
* Are evaluating HASP as a drop-in replacement for direct Anthropic calls.
* Are building a prototype and want to defer the native migration.

The migration from compat to native is a single endpoint change plus adopting the HASP error vocabulary. No compliance or PHI-handling capabilities are lost by starting on compat.

## Migrating from compat to native

```diff theme={null}
- import Anthropic from '@anthropic-ai/sdk';
- const client = new Anthropic({ baseURL: 'https://api.usehasp.com', apiKey: process.env.HASP_API_KEY });
- const msg = await client.messages.create({ model: 'claude-sonnet-4-6', ... });
+ // The native surface is REST — call it directly
+ const res = await fetch('https://api.usehasp.com/v1/ai/chat', {
+   method: 'POST',
+   headers: { Authorization: `Bearer ${process.env.HASP_API_KEY}`, 'Content-Type': 'application/json' },
+   body: JSON.stringify({ model: 'claude-sonnet-4-6', messages: [...] }),
+ });
```

The response shape differs: native responses include `meta.request_id` at top level and `meta.phi` if redaction was applied. Anthropic-compat responses follow the standard Anthropic shape with `id` as the request identifier.

## What's the same on both surfaces

* **All compliance checks run.** PHI scanning, BAA validation, credit checks, and audit logging are identical on both surfaces. You cannot bypass compliance by using the compat endpoint.
* **Same API keys.** The same `hasp_api_live_*` key works on both surfaces with the `ai:chat` scope.
* **Same model identifiers.** The HASP model name (`claude-sonnet-4-6`) is the same on both.
* **Same request\_id.** The `id` field on compat responses and the `meta.request_id` on native responses resolve to the same record via `GET /v1/ai/messages/{id}`.
