Skip to main content

Installation

To use Aleph Alpha with Netra SDK, install both packages:
pip install netra-sdk aleph-alpha-client
The Netra SDK automatically instruments Aleph Alpha API calls when initialized, providing comprehensive tracing and observability for your language model interactions.

Usage

Basic Setup

Initialize the Netra SDK with your API key to enable automatic instrumentation of Aleph Alpha calls.
from netra import Netra

# Initialize Netra with your API key
Netra.init(
    app_name="my-aleph-alpha-app",
    headers=f"x-api-key={os.environ['NETRA_API_KEY']}",
    trace_content=True
)

# Your Aleph Alpha code will be automatically traced

Working with Aleph Alpha Completions

Once initialized, all Aleph Alpha API calls are automatically traced with detailed telemetry including prompts, completions, token usage, and timing information.
from netra import Netra
from aleph_alpha_client import Client, CompletionRequest, Prompt
import os

# Initialize Netra
Netra.init(
    app_name="my-aleph-alpha-app",
    headers=f"x-api-key={os.environ['NETRA_API_KEY']}",
    trace_content=True
)

# Use Aleph Alpha normally - automatically traced
client = Client(token=os.environ["ALEPH_ALPHA_API_KEY"])

request = CompletionRequest(
    prompt=Prompt.from_text("What is AI?"),
    maximum_tokens=100
)

response = client.complete(request, model="luminous-base")
print(response.completions[0].completion)

Using Decorators for Custom Workflows

Enhance tracing with Netra decorators to track custom workflows, agents, and tasks alongside Aleph Alpha calls.
from netra import Netra, workflow, task
from aleph_alpha_client import Client, CompletionRequest, Prompt

Netra.init(
    headers=f"x-api-key={os.environ['NETRA_API_KEY']}"
)

client = Client(token=os.environ["ALEPH_ALPHA_API_KEY"])

@workflow()
def process_document(text: str):
    summary = summarize_text(text)
    keywords = extract_keywords(summary)
    return {"summary": summary, "keywords": keywords}

@task()
def summarize_text(text: str):
    request = CompletionRequest(
        prompt=Prompt.from_text(f"Summarize: {text}"),
        maximum_tokens=150
    )
    response = client.complete(request, model="luminous-extended")
    return response.completions[0].completion

@task()
def extract_keywords(text: str):
    request = CompletionRequest(
        prompt=Prompt.from_text(f"Extract keywords: {text}"),
        maximum_tokens=50
    )
    response = client.complete(request, model="luminous-base")
    return response.completions[0].completion

Session Tracking

Track user sessions and conversations when using Aleph Alpha for conversational applications.
from netra import Netra, ConversationType

# Start a user session
Netra.start_session(
    session_id="user-session-123",
    user_id="user-456",
    metadata={"app": "chatbot"}
)

# Start a conversation
Netra.start_conversation(
    conversation_type=ConversationType.CHAT,
    metadata={"topic": "AI"}
)

# Add messages to the conversation
Netra.add_message(role="user", content="Tell me about Aleph Alpha")

# Your Aleph Alpha call here...

# End conversation when done
Netra.end_conversation()

Next Steps

Explore additional Netra SDK capabilities to enhance your Aleph Alpha integration:
Last modified on January 30, 2026