OpenAI SDK

Use the official OpenAI Python or Node.js SDK with Pura LLM by setting base_url and api_key.

Drop-in replacement

Pura LLM is a drop-in replacement for OpenAI. Change two lines of configuration and your existing code works unchanged.

Python

Install the official openai package and configure the client:

Install
pip install openai
python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://llm.puradigital.it/v1",
)

response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain EU data residency in one sentence."},
    ],
)

print(response.choices[0].message.content)

Streaming

Streaming responses are fully supported:

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://llm.puradigital.it/v1",
)

stream = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Write a haiku about privacy."}],
    stream=True,
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

Node.js / TypeScript

Install the openai npm package:

Install
npm install openai
typescript
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.PURA_LLM_API_KEY,
  baseURL: "https://llm.puradigital.it/v1",
});

const completion = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Hello from the OpenAI SDK!" }],
});

console.log(completion.choices[0].message.content);

Embeddings

Generate embeddings using the same client:

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://llm.puradigital.it/v1",
)

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="Document text to embed",
)

print(len(response.data[0].embedding))

List models

Retrieve the available model catalog programmatically:

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://llm.puradigital.it/v1",
)

models = client.models.list()
for model in models.data:
    print(model.id)

Environment variables

Many tools read OPENAI_API_KEY and OPENAI_BASE_URL automatically:

.env
OPENAI_API_KEY=YOUR_API_KEY
OPENAI_BASE_URL=https://llm.puradigital.it/v1

Inference traceability: compliance_metadata v1

Contract for the compliance-enabled gateway. Each deployment must pass the conformity gate before activation; the current catalog is not yet certified.

The v2 contract guarantees provider, actual model, EU data_zone, ingress_region, original upstream_request_id, gateway_request_id and UTC timestamp. The ingress region does not identify the execution region: Azure Data Zone Standard and Bedrock geographic profiles can distribute requests across certified zone regions. The region field remains reserved for regional v1 deployments.

provider_raw is best effort: its presence, structure and completeness are not guaranteed. It contains only metadata permitted by provider-specific allowlists. Do not use it as a contractual dependency.

Read the gateway contract and examples

For completed requests we record stable traceability fields without prompts, responses or provider_raw. Details are available in Logs after activating the integration. Historical logs and failed deliveries may lack this metadata.