Skip to main content
Anthropic-compatible drop-in endpoint. Change one line in your existing @anthropic-ai/sdk code and everything works. Requires the ai:chat scope.

Migrating from Anthropic

import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  baseURL: 'https://api.usehasp.com',  // ← only this line changes
  apiKey: 'hasp_key_live_...',
});
Request shape, response shape, streaming events, and tool use are Anthropic’s exact wire format. Your existing code, types, and tooling continue to work.

Request

POST https://api.usehasp.com/v1/messages
Authorization: Bearer hasp_key_live_...
Content-Type: application/json
The request body is identical to Anthropic’s Messages API. Key fields:
ParameterTypeDescription
modelstringModel ID — same identifiers as Anthropic (claude-sonnet-4-6, etc.)
messagesarrayConversation turns: [{"role": "user", "content": "..."}]
max_tokensintegerRequired by Anthropic’s spec.
streambooleantrue for SSE, false for a single JSON response.
systemstringSystem prompt.
toolsarrayTool definitions (same format as Anthropic).

Streaming events

When stream: true, the event stream uses Anthropic’s exact wire format:
event: message_start
event: content_block_start
event: content_block_delta   (repeated)
event: content_block_stop
event: message_delta
event: message_stop
event: ping                  (keep-alive)
event: error                 (on failure)
This means libraries and utilities that parse Anthropic SSE streams work without modification.

Compliance behavior

All HASP compliance checks apply — PHI Guard, BAA enforcement, credit metering — regardless of which endpoint you use. Compliance is a property of your organization, not the endpoint shape.
  • PHI Guard runs on all messages. If phi_mode=redact (default), PHI is replaced with placeholders before the upstream call. If phi_mode=block, the request returns 403 PHI_BLOCKED using the HASP error envelope.
  • BAA required. No active BAA → 402 BAA_REQUIRED on every request.
  • Credit metering. Credits are deducted after each successful response. Exhausted credits → 402 AI_CREDITS_EXHAUSTED.

Native-only flags are rejected

Parameters that exist in the native /v1/ai/chat endpoint but not in Anthropic’s wire format are rejected with 400 UNSUPPORTED_PARAMETER rather than silently accepted:
  • store — use POST /v1/ai/chat if you need stateless (no-content-storage) requests.
  • Any other non-Anthropic field.
This keeps the contract honest — if you send store: false and get a 200 back, you might wrongly assume the content wasn’t stored.

Graduating to native features

Customers using /v1/messages can migrate endpoint-by-endpoint to /v1/ai/chat to gain:
  • store: false for stateless requests
  • PHI entity metadata in responses
  • Run and conversation management
  • Tool use (future phase)
No breaking changes are required for the migration — the two endpoints are independent.

Error codes

CodeHTTPDescription
INVALID_API_KEY401Missing or revoked token
BAA_REQUIRED402No active BAA
AI_CREDITS_EXHAUSTED402Credit allotment exhausted
MISSING_SCOPE403Key lacks ai:chat scope
PHI_BLOCKED403PHI detected and phi_mode=block is configured
OPUS_NOT_ENABLED403Opus model not enabled for this org
UNSUPPORTED_PARAMETER400Non-Anthropic parameter sent (e.g. store)
RATE_LIMITED429RPM or daily limit exceeded
INFERENCE_UPSTREAM_FAILURE502Upstream model provider error — retryable