Skip to main content

API for ibl.ai — generative AI backend as a service for educators.

Project description

iblai

API for ibl.ai — a generative AI backend as a service for educators.

Requirements

Python 3.9+

Installation & Usage

pip install

To install the API client library, simply execute:

pip install iblai

Then import the package:

import iblai

Getting Started

Please follow the installation procedure and then run the following:

Authentication

The SDK requires a Platform API Key for authentication. This is different from JWT tokens or user session tokens.

How to obtain your Platform API Key:

  1. Log in to your ibl.ai admin dashboard
  2. Navigate to SettingsAPI Keys
  3. Create or copy an existing Platform API Key

Important notes:

  • The API key is tenant-specific and user-specific
  • The SDK automatically uses the Api-Token authorization header format
  • Token format: 64-character hexadecimal string (e.g., 5223a68d...cf29)
# Platform API Key - obtain from ibl.ai dashboard → Settings → API Keys
# Must be associated with the tenant and username you're using
api_token = "your-64-character-platform-api-key"

Adding LLM credentials

from iblai.helpers import add_llm_credential

base_url = "https://base.manager.iblai.app"
api_token = "your-platform-api-key"  # Platform API Key from dashboard

credential_name = "openai"
credential_value = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
tenant = "new-platform"

add_llm_credential(credential_name, credential_value, tenant, api_token, base_url)

Chatting with a mentor

import asyncio
from iblai.helpers import (
    create_mentor,
    upload_document_to_mentor,
    wait_for_document_training_to_complete,
    create_chat_session,
    chat_with_mentor_async
)

async def main():
    tenant = "new-platform"
    username = "my-user"
    base_url = "https://base.manager.iblai.app"
    asgi_base_url = "wss://asgi.data.iblai.app"
    api_token = "your-platform-api-key"  # Platform API Key from dashboard

    mentor_name = "My New Mentor"
    # Available template names: "ai-mentor", "mentorAI"
    # Templates define default settings, prompts, and behaviors for the mentor
    mentor_settings = {
        "template_name": "ai-mentor",  # Required: the template to base the mentor on
        "new_mentor_name": mentor_name,
        "display_name": mentor_name,
    }

    mentor_data = await create_mentor(tenant, username, mentor_settings, api_token, base_url)

    # Extract unique_id - required for document operations and chat
    mentor_unique_id = mentor_data["unique_id"]

    await upload_document_to_mentor(
        mentor_name=mentor_unique_id,  # Must use unique_id, not the display name
        file_path="doc.pdf",
        tenant=tenant,
        username=username,
        api_token=api_token,
        base_url=base_url
    )

    await wait_for_document_training_to_complete(
        mentor_name=mentor_unique_id,
        tenant=tenant,
        username=username,
        api_token=api_token,
        base_url=base_url
    )

    session_id = await create_chat_session(
        mentor_name=mentor_unique_id,
        tenant=tenant,
        username=username,
        base_url=base_url
    )

    prompt = "What is the main topic of the document?"
    async for token in chat_with_mentor_async(
        prompt, session_id, mentor_unique_id, tenant, username, api_token, asgi_base_url
    ):
        print(token, end="")

asyncio.run(main())

Inviting a user

from iblai.helpers import invite_user_to_platform

base_url = "https://base.manager.iblai.app"
api_token = "your-platform-api-key"  # Platform API Key from dashboard

tenant = "new-platform"
email = "new-student@example.com"

invite_user_to_platform(tenant, email, api_token, base_url)

Error Handling

Common errors and their solutions:

HTTP Status Error Message Cause Solution
401 {"detail":"Invalid token."} Invalid API token or token doesn't match tenant/username Verify your Platform API Key is correct and associated with the tenant/user
400 {"template_name":["This field is required."]} Missing template_name in mentor_settings Add "template_name": "ai-mentor" to your settings
400 {"error":"Document pathway (name) is not a valid mentor unique id"} Using mentor display name instead of unique_id Use mentor_data["unique_id"] for document operations
400 {"error":"Template mentor X not found."} Invalid template_name value Use a valid template: "ai-mentor" or "mentorAI"

Example with error handling:

mentor_data = await create_mentor(
    tenant=tenant,
    username=username,
    settings=mentor_settings,
    api_token=api_token,
    base_url=base_url,
)

if mentor_data is None:
    print("Failed to create mentor - check API token, tenant, username, and template_name")
    return

# Proceed with the unique_id
mentor_unique_id = mentor_data["unique_id"]
print(f"Mentor created successfully: {mentor_unique_id}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iblai-4.202.2.tar.gz (854.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iblai-4.202.2-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file iblai-4.202.2.tar.gz.

File metadata

  • Download URL: iblai-4.202.2.tar.gz
  • Upload date:
  • Size: 854.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for iblai-4.202.2.tar.gz
Algorithm Hash digest
SHA256 a79099c9f5b96974be209528763c22778026081fac108d0156a72fa3f70420e8
MD5 a35ed2d9e934e6c95ee1492cb2be8b88
BLAKE2b-256 b1f320e8a8f5b3abc597df21f4c5a37e870c55638aba24add610260cce10e49e

See more details on using hashes here.

File details

Details for the file iblai-4.202.2-py3-none-any.whl.

File metadata

  • Download URL: iblai-4.202.2-py3-none-any.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for iblai-4.202.2-py3-none-any.whl
Algorithm Hash digest
SHA256 81e9025af7acf4de93cd6fb671e6c8edf2c487d361c4bfa07cdebd6864205e9c
MD5 5195be8c41f5fe66b0031b7e45fed95e
BLAKE2b-256 5737f0cdf76e3c75909129d4330e48d566685b8660e93ee30ac447611aa183f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page