Skip to main content

vitaai · Python SDK

Python SDK for VitaAI self-hosted LLM endpoints.
Works just like the Google Gemini SDK — client.models.method() pattern with a stream parameter on every endpoint.


Install

pip install vitaai
pip install requests  # required for image endpoints

Quick start

from vitaai import VitaAI

client = VitaAI(
    base_url="http://your-server-ip:8000",
    api_key="your-api-key"   # optional — not required if server has no auth
)

response = client.models.generate_content(
    model="gemma-4-E2B-it",
    contents="What is AI?",
    max_output_tokens=100
)
print(response.text)
print("Tokens:", response.usage_metadata.total_token_count)

Client parameters

Parameter Type Default Description
base_url str https://api.vitaai-api.com Your self-hosted server URL
api_key str None Optional API key. Or set VITAAI_API_KEY env var
timeout int 120 Request timeout in seconds

Streaming

Every endpoint supports a stream parameter:

  • stream=False (default) — waits and returns the full response object
  • stream=True — yields tokens live as the model generates them
# Normal — full response at once
r = client.models.generate_content(model="gemma-4-E2B-it", contents="What is AI?")
print(r.text)

# Streaming — tokens print live
for chunk in client.models.generate_content(model="gemma-4-E2B-it", contents="What is AI?", stream=True):
    print(chunk.text, end="", flush=True)

Endpoints

1. Generate content

r = client.models.generate_content(
    model="gemma-4-E2B-it",
    contents="What is machine learning?",
    max_output_tokens=150,
    stream=False,  # default
)
print(r.text)
print("Tokens:", r.usage_metadata.total_token_count)

With config (system instruction, temperature, etc.)

r = client.models.generate_content(
    model="gemma-4-E2B-it",
    contents="Explain deep learning",
    config={
        "system_instruction": "You are a teacher. Explain simply.",
        "temperature": 0.7,
        "top_p": 0.9,
        "max_output_tokens": 200,
    }
)
print(r.text)

Multi-turn conversation

r = client.models.generate_content(
    model="gemma-4-E2B-it",
    contents=[
        {"role": "user",  "parts": [{"text": "My name is Alex."}]},
        {"role": "model", "parts": [{"text": "Nice to meet you, Alex!"}]},
        {"role": "user",  "parts": [{"text": "What is my name?"}]},
    ]
)
print(r.text)

Streaming

for chunk in client.models.generate_content(
    model="gemma-4-E2B-it",
    contents="Write a short poem.",
    max_output_tokens=100,
    stream=True,
):
    print(chunk.text, end="", flush=True)
Response field Type Description
r.text str Full generated text
r.usage_metadata.prompt_token_count int Input tokens
r.usage_metadata.candidates_token_count int Output tokens
r.usage_metadata.total_token_count int Total tokens

2. Summarize

# Normal
r = client.models.summarize(
    contents="Long article text here...",
    format="bullets",       # "paragraph" or "bullets"
    max_output_tokens=150,
)
print(r.summary)

# Streaming
for chunk in client.models.summarize(contents="Long article...", format="paragraph", stream=True):
    print(chunk.text, end="", flush=True)
Parameter Type Default Description
contents str — Text to summarize
format str "paragraph" "paragraph" or "bullets"
max_output_tokens int 200 Max summary length
stream bool False Stream tokens live
Response field Type Description
r.summary str Summarized text
r.format str Format used
r.usage_metadata.total_token_count int Total tokens

3. Embeddings

r = client.models.embed_content(
    contents="Artificial intelligence is transforming the world."
)
print("Dimensions:", len(r.embedding.values))
print("Vector:", r.embedding.values[:5])
Response field Type Description
r.embedding.values List[float] The embedding vector

4. Analyze image

# Normal
r = client.models.analyze_image(
    file_path="photo.jpg",
    prompt="What objects are visible in this image?",
    max_output_tokens=512,
)
print(r.analysis)

# Streaming
for chunk in client.models.analyze_image(file_path="photo.jpg", prompt="What do you see?", stream=True):
    print(chunk.text, end="", flush=True)
Parameter Type Default Description
file_path str — Path to image (JPG, PNG, WEBP, GIF)
prompt str — Question or instruction
system_instruction str None Optional system prompt
temperature float 1.0 Sampling temperature
max_output_tokens int 512 Max response length
image_token_budget int 280 Detail level: 70/140/280/560/1120
stream bool False Stream tokens live
Response field Type Description
r.analysis str Model's analysis
r.image_info.size tuple Image dimensions
r.usage_metadata.total_token_count int Total tokens

5. Describe image

# Normal
r = client.models.describe_image(file_path="photo.jpg", max_output_tokens=512)
print(r.description)

# Streaming
for chunk in client.models.describe_image(file_path="photo.jpg", stream=True):
    print(chunk.text, end="", flush=True)
Response field Type Description
r.description str Full image description
r.image_info.size tuple Image dimensions
r.usage_metadata.total_token_count int Total tokens

6. OCR — extract text from image

# Normal
r = client.models.ocr_image(file_path="document.png", language="English")
print(r.extracted_text)

# Streaming
for chunk in client.models.ocr_image(file_path="document.png", stream=True):
    print(chunk.text, end="", flush=True)
Parameter Type Default Description
file_path str — Path to image
language str "English" Language of text in image
max_output_tokens int 512 Max response length
image_token_budget int 560 Higher = better OCR accuracy
stream bool False Stream tokens live
Response field Type Description
r.extracted_text str All text found in image
r.image_info.language str Language used
r.usage_metadata.total_token_count int Total tokens

7. Ping

r = client.models.ping()
print(r.status)   # "ok"
print(r.model)    # "gemma-4-E2B-it"
print(r.device)   # "CUDA"
print(r.version)  # "2.3.0"
print(r.limits.max_input_tokens)
print(r.limits.max_output_tokens)

8. Health

r = client.models.health()
print(r.status)          # "healthy"
print(r.cuda_available)  # True / False
print(r.limits.max_input_tokens)
print(r.limits.max_output_tokens)

9. Stats

s = client.models.stats()
print(s.device)                    # "CUDA"
print(s.gpu_name)                  # "Tesla T4"
print(f"{s.gpu_memory_total_gb:.1f} GB")
print(f"{s.gpu_memory_allocated_gb:.1f} GB")

10. List models

for m in client.models.list():
    print(m["name"])
    print(m["capabilities"])
    print(m["max_output_tokens"])

Error handling

from vitaai.transport import AuthenticationError, ServerError, VitaAIError

try:
    r = client.models.generate_content(model="gemma-4-E2B-it", contents="Hello")
    print(r.text)
except AuthenticationError:
    print("Invalid API key")
except ServerError as e:
    print(f"Server error ({e.status_code}): {e}")
except VitaAIError as e:
    print(f"Error: {e}")

Server endpoints

Method Path stream support
GET / —
GET /health —
GET /v1/stats —
GET /v1/models/list —
POST /v1/models/generate ✅ ?stream=true
POST /v1/models/summarize ✅ ?stream=true
POST /v1/models/embed —
POST /v1/models/analyze-image ✅ ?stream=true
POST /v1/models/describe-image ✅ ?stream=true
POST /v1/models/ocr-image ✅ ?stream=true

Environment variables

Variable Description
VITAAI_API_KEY API key (alternative to api_key= parameter)
VITAAI_BASE_URL Server URL (alternative to base_url= parameter)

Metadata

Release files for vitaai 1.0.1

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

Source distribution (sdist)

Source distribution for vitaai 1.0.1
File Size Uploaded Provenance Actions
vitaai-1.0.1.tar.gz 24.4 kB Without provenance Details for vitaai-1.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 50.9 kB

Release files / vitaai-1.0.1.tar.gz

Download URL vitaai-1.0.1.tar.gz
Size 24.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c6d002aebb4c722afe5609faf11a5b0037efa17c1d78d63ff4eca60056aa9bed
BLAKE2b-256 checksum
How to use checksums
ffc68869cbf6e4a7d942bb5561b858973c8ce30dcbd6e0a428331e7f3e9ac399
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / vitaai-1.0.1-py3-none-any.whl

Download URL vitaai-1.0.1-py3-none-any.whl
Size 26.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bbeba7ecb6e37032c7c1a7e774808b93abe4ea36b1bfc99f112456fe8760ece2
BLAKE2b-256 checksum
How to use checksums
e7b5888540d2c2ba0c598070ee3818f8dc3100c295548fc37cd8ef7b925a9ef1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Security for vitaai 1.0.1

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.

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