Skip to main content

Python client for the Nova AI API

Project description

Python SDK

Python client for the Nova AI API.

The package is intentionally small:

  • sync methods
  • no external dependencies
  • typed request and response structures
  • simple streaming support for chat completions with a normal for loop
  • audio helpers for transcription, translation, and speech generation

Install

pip install datalabrotterdam-nova-sdk

Create A Client

from nova_ai import NovaAIClient

client = NovaAIClient(
    api_key="sk_live_..."
)

If you do not pass base_url, the client uses https://api.nova.datalabrotterdam.nl/v1.

Example: Normal Chat

from nova_ai import NovaAIClient

client = NovaAIClient(
    api_key="sk_live_..."
)

completion = client.chat.completions.create({
    "model": "llama3.2",
    "messages": [
        {"role": "system", "content": "You are helpful."},
        {"role": "user", "content": "Explain embeddings in one sentence."}
    ],
    "max_tokens": 256,
    "temperature": 0.7,
})

print(completion["choices"][0]["message"]["content"])
print(completion.get("usage_source"))
print(completion.get("metrics", {}).get("tokens_per_second"))

completion["usage_source"] is:

  • "provider" when the upstream provider reported usage
  • "gateway_estimated" when Nova AI estimated usage to keep the contract consistent

Example: Streaming Chat

from nova_ai import NovaAIClient, collect_chat_text

client = NovaAIClient(
    api_key="sk_live_..."
)

stream = client.chat.completions.stream({
    "model": "llama3.2",
    "messages": [{"role": "user", "content": "Write three short tips."}]
})

for event in stream:
    if event["type"] == "chunk":
        choices = event["data"].get("choices", [])
        if choices:
            print(choices[0].get("delta", {}).get("content", ""), end="")

print()

print(collect_chat_text(client.chat.completions.stream({
    "model": "llama3.2",
    "messages": [{"role": "user", "content": "Summarize vectors in one line."}]
})))

Example: Embeddings

from nova_ai import NovaAIClient

client = NovaAIClient(
    api_key="sk_live_..."
)

embedding = client.embeddings.create({
    "model": "nomic-embed-text",
    "input": "Nova AI"
})

print(len(embedding["data"][0]["embedding"]))

Example: Audio Transcription

from nova_ai import NovaAIClient

client = NovaAIClient(
    api_key="sk_live_..."
)

transcript = client.audio.transcriptions.create(
    file_path="./sample.wav",
    model="whisper-1",
    language="nl",
)

print(transcript["text"])

Example: Speech Synthesis

from nova_ai import NovaAIClient

client = NovaAIClient(
    api_key="sk_live_..."
)

audio = client.audio.speech.create({
    "model": "tts-1",
    "input": "Hello from Nova AI",
    "voice": "alloy",
    "response_format": "wav",
})

with open("speech.wav", "wb") as target:
    target.write(audio)

Included Methods

  • client.providers.list()
  • client.models.list(limit=None, after=None)
  • client.chat.completions.create(payload, config_id=None, request_id=None)
  • client.chat.completions.stream(payload, config_id=None, request_id=None)
  • client.embeddings.create(payload, config_id=None, request_id=None)
  • client.audio.transcriptions.create(file_path=..., model=..., ...)
  • client.audio.translations.create(file_path=..., model=..., ...)
  • client.audio.speech.create(payload, config_id=None, request_id=None)

Audio Notes

  • client.audio.transcriptions.create() and client.audio.translations.create() upload audio as multipart/form-data.
  • client.audio.speech.create() returns raw bytes.
  • The gateway enforces runtime scopes:
    • audio:transcribe
    • audio:translate
    • audio:synthesis

Why streaming uses for, not async for

For this Python SDK, a normal iterator is the simplest way to support streaming without extra dependencies. That means you can stream like this:

for event in client.chat.completions.stream({...}):
    ...

Using async for is also possible, but it usually means introducing an async HTTP client such as httpx or aiohttp, which makes the first version of the SDK heavier.

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

datalabrotterdam_nova_sdk-1.5.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

datalabrotterdam_nova_sdk-1.5.1-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file datalabrotterdam_nova_sdk-1.5.1.tar.gz.

File metadata

File hashes

Hashes for datalabrotterdam_nova_sdk-1.5.1.tar.gz
Algorithm Hash digest
SHA256 6af718d4b3e207e61c71a1d8990d6a83c4c34c4020ff1a06f8db0d21f45095e9
MD5 4443f897bcab257254ae30b019a89a86
BLAKE2b-256 36b7ba6378b11a5fd9ad51eba2c143b8b000e0ff35065521655354c8c7b992ad

See more details on using hashes here.

File details

Details for the file datalabrotterdam_nova_sdk-1.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for datalabrotterdam_nova_sdk-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 79d0932a27583c692a7dcdd959cdb8fc94216f3bc3bd1590f93e9804c064bd4d
MD5 ed4df0c6887bedee81ade91701b5f0dd
BLAKE2b-256 5d9e5cfcbf454435fe055c3f95c236370970c90605347588ffa928f65ab49da3

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