Skip to main content

Install

The SDK is available on npm. It requires Node.js 24.22.1 or later for Node usage.
Set your API key in the environment:

Examples

Choose the tab matching your model’s API. Save the example as example.mjs and run it with node example.mjs.
Call a supported NEAR TEE model with E2EE enabled, then verify the completion.

E2EE

End-to-end encryption is disabled by default. Set e2ee: true to encrypt supported Chat fields to a verified model key and decrypt the response automatically. E2EE requires a supported NEAR TEE model; leave it disabled for other models and APIs.

Verification

InferenceClient verifies the Gateway and every returned NEAR model-attestation candidate before sending an E2EE Chat Completion. Call verifyResponse() after a completion to verify its response signature with the request and response bytes captured by the client.
verifyResponse() is explicit. For a streaming completion, consume the entire stream first, then call it with the completion ID so the SDK can verify the exact response bytes.

Set a TCB policy

By default, the SDK accepts the Intel TCB statuses UpToDate and OutOfDate. To require UpToDate, apply a policy to both the Gateway and model evidence:

Runtime behavior

For Node, import from @nearai/inference-sdk/node. It verifies the Gateway TLS peer and binds later requests to the verified Gateway identity. For a browser or application proxy, import from @nearai/inference-sdk; browser Fetch cannot read the TLS peer certificate, so that entry point does not perform Gateway TLS binding. Response records expire after 60 minutes by default. Verify each response before its record expires or you dispose of the client. See the SDK overview for receipt IDs and signature kinds, or Verification for custom policies.

OHTTP

Set ohttp: true to encapsulate Chat requests and responses with OHTTP. OHTTP uses the SDK’s default Ed25519 signing algorithm; it is not compatible with signingAlgo: 'ecdsa'.
The Chat and verifyResponse() calls stay the same. Before sending Chat, the SDK verifies the Gateway’s signed OHTTP configuration; a missing or invalid configuration blocks the request. OHTTP encapsulates the exchange to the Gateway, while E2EE encrypts supported Chat fields to the verified model key.
OHTTP supports Chat Completions, Responses, and Messages through the Gateway; System One does not support OHTTP. Attestation and signature requests remain regular HTTPS. The configured endpoint or proxy must expose /ohttp at the same origin. Authorization and custom headers sent on the outer request, along with the client’s network address, are not hidden by OHTTP.

Examples and reference

See the Inference SDK examples and setup instructions for runnable projects.