Skip to main content

adityalab — Python client for the Aditya API

The official Python library for Aditya, a family of AI models built for Indian languages.

pip install adityalab

Python 3.9+. Its only dependency is httpx.

Quick start

Create an API key at platform.adityalab.in, then:

export ADITYA_API_KEY="bk_..."
from adityalab import Aditya

client = Aditya()   # reads ADITYA_API_KEY

reply = client.chat.completions.create(
    model="aditya-latest",
    messages=[{"role": "user", "content": "Explain an API in Hindi."}],
)
print(reply.text)

reply is the standard chat-completion object, so reply.choices[0].message.content and reply.usage.total_tokens work too.

Streaming

with client.chat.completions.create(
    model="aditya-latest",
    messages=[{"role": "user", "content": "Tell me a short story in Tamil."}],
    stream=True,
) as stream:
    for piece in stream.text():
        print(piece, end="", flush=True)

To read the raw chunks instead of only the text, iterate stream directly.

Conversations kept on the server

Pass conversation="new" on the first call. After that, send only the new message with the returned id, and the server supplies the earlier turns:

first = client.chat.completions.create(
    model="aditya-latest",
    messages=[{"role": "user", "content": "मेरा नाम रिया है।"}],
    conversation="new",
)
cid = first.conversation_id

second = client.chat.completions.create(
    model="aditya-latest",
    messages=[{"role": "user", "content": "मेरा नाम क्या है?"}],
    conversation=cid,
)
print(second.text)

Calls without conversation are stateless, and nothing is stored.

To list, read and delete stored conversations:

for conv in client.conversations.iter():
    print(conv.id, conv.title)

page = client.conversations.messages(cid)      # .items, .nextAfter
client.conversations.delete(cid)

Models, credits and pricing

client.models.list()          # the models your key can call
client.credits.balance()      # .balance (in credits), .planTier
client.credits.usage()        # spend over the last 5 hours, day and 30 days
client.pricing.retrieve()     # public price list

Async

import asyncio
from adityalab import AsyncAditya

async def main():
    async with AsyncAditya() as client:
        reply = await client.chat.completions.create(
            model="aditya-latest", messages=[{"role": "user", "content": "नमस्ते"}])
        print(reply.text)

        stream = await client.chat.completions.create(
            model="aditya-latest", messages=[{"role": "user", "content": "नमस्ते"}], stream=True)
        async for piece in stream.text():
            print(piece, end="")

asyncio.run(main())

Errors

Every API error is raised as a typed exception. Each one has .status_code, .code (a stable string to branch on), .message and .request_id; quote the request id when you contact support.

import adityalab

try:
    client.chat.completions.create(model="aditya-latest", messages=[...])
except adityalab.InsufficientCreditsError:
    ...  # top up at platform.adityalab.in
except adityalab.RateLimitError as e:
    ...  # e.code == "window_cap_reached" means your plan's 5-hour window is used up; see e.retry_after
except adityalab.AuthenticationError:
    ...  # wrong, revoked or expired key
except adityalab.APIConnectionError:
    ...  # network trouble, or a timeout (APITimeoutError)
Exception When
BadRequestError 400: the request is malformed
AuthenticationError 401: missing, invalid, revoked or expired key
InsufficientCreditsError out of credits
PermissionDeniedError 403
NotFoundError 404: unknown model or conversation
RateLimitError 429
InternalServerError 5xx, including a busy model (model_busy)
StreamError the model stopped partway through a stream

Retries and timeouts

The client retries automatically, up to max_retries times (default 2):

  • a busy model or rate limit (the server refused before doing any work);
  • 5xx errors on reads;
  • network errors.

It never re-sends a conversation turn after the server may have stored it. It also does not wait out a long Retry-After, such as a used-up usage window; you get the error straight away.

client = Aditya(timeout=60, max_retries=3)
client.chat.completions.create(..., timeout=10)   # per call

OpenAI compatibility

The API is also OpenAI-compatible, so existing OpenAI code works with base_url="https://api.adityalab.in/v1". Use this library to get typed errors, server-side conversations, and the credits and pricing calls.

Configuration

Option Environment variable Default
api_key ADITYA_API_KEY none (required)
base_url ADITYA_BASE_URL https://api.adityalab.in/v1
timeout none 120 seconds
max_retries none 2

Pass http_client=httpx.Client(...) to set up proxies or custom TLS.

License

Apache-2.0

Metadata

Release files for adityalab 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adityalab 0.1.0
File Size Uploaded Provenance
adityalab-0.1.0.tar.gz 16.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for adityalab 0.1.0
File Interpreter ABI Platform
adityalab-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 33.5 kB

Release files / adityalab-0.1.0.tar.gz

Download URL adityalab-0.1.0.tar.gz
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
aad7f7dc5f1f658117d9d78e83045558c4551cd7689df7d63411e166a653bad6
BLAKE2b-256 checksum
How to use checksums
9797a6902beb084cea0b7a7c82650eb31926eb3b591388e872d074cc01ba84e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / adityalab-0.1.0-py3-none-any.whl

Download URL adityalab-0.1.0-py3-none-any.whl
Size 16.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f9c5d97cb5fd998a5ab0d3b7f9f1ba77f057d4135682c5d978c181ca1a80db1
BLAKE2b-256 checksum
How to use checksums
f0154b62698a53c8e23947bd31b7cf6baf7b124dc695782e06ee6fbf14c17a46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for adityalab 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page