Skip to content
PuraPura Developers
Developers/Quickstart

Quickstart

From the first connection to the first inference, with a per-user backend.

Prerequisites

You need a Pura account, an active paid subscription, a registered app and an exact HTTPS redirect under your control. Configure a test environment with users and callbacks separate from production.

Install the SDK release

Obtain the official package for the agreed version from Pura and verify its SHA-256 manifest before installation. An OpenAI SDK is not required for delegated inference.

bash
npm install ./pura-ai-sdk-0.1.0.tgz
# Python
pip install ./pura_llm_sdk-0.1.0-py3-none-any.whl

Connect the user

Generate authorization for the local session, save pending state on your server and redirect the browser. On return, validate state, redirect and PKCE through the SDK. Save tokens only after binding the verified pura_user_id to the authenticated local user.

typescript
import {createAuthorization, PuraOAuthClient} from '@pura-ai/sdk';

const options = {
  apiBase: 'https://ai.puradigital.it/v1',
  clientId: process.env.PURA_CLIENT_ID!,
  redirectUri: 'https://your-app.example/pura/callback',
};
const {url, pending} = await createAuthorization(options);
// Save pending in the authenticated user's server session.
// Redirect that browser to url.

const oauth = new PuraOAuthClient({
  ...options, clientSecret: process.env.PURA_CLIENT_SECRET!,
});
const tokens = await oauth.exchange(callbackUrl, pending);
// Bind tokens.pura_user_id to the authenticated local user.
await userTokenStore.set(tokens);

Send the first request

The example TokenStore is an adapter to implement with your database. Use a client bound to the current user’s connection and check available services with capabilities(). The client does not select a model.

typescript
import {PuraInferenceClient} from '@pura-ai/sdk';

const pura = new PuraInferenceClient({
  apiBase: 'https://ai.puradigital.it/v1',
  clientId: process.env.PURA_CLIENT_ID!,
  clientSecret: process.env.PURA_CLIENT_SECRET!,
  store: userTokenStore,
});
const answer = await pura.chat({
  
  messages: [{role: 'user', content: 'Hello, Pura'}],
});
const usage = await pura.usage();

Before production

Implement token encryption, concurrent refresh handling, 402/429 handling, disconnection and webhooks. Verify two users and two apps on the same account: usage must remain shared and revocations separate.