Skip to main content

Python SDK for VitaAI self-hosted LLM endpoints — drop-in Gemini API replacement

Project description

vitaai · Python SDK

Drop-in Python SDK for VitaAI self-hosted LLM endpoints.
Designed to mirror the Google Gemini SDK interface exactly — so migrating existing Gemini projects takes changing one import.

Base URL: https://api.vitaai-api.com

Install

pip install vitaai            # stdlib only (urllib)
pip install vitaai[requests]  # recommended — better streaming

Quick start

from vitaai import VitaAI

client = VitaAI(api_key="your-key")
# or set VITAAI_API_KEY env var and just call VitaAI()

response = client.models.generate_content(
    model="gemma3-27b",
    contents="Explain how AI works in a few words",
)
print(response.text)

Usage

Generate content

response = client.models.generate_content(
    model="gemma3-27b",
    contents="What is the capital of France?",
)
print(response.text)                          # "Paris"
print(response.usage_metadata.total_token_count)

Multi-turn conversation

response = client.models.generate_content(
    model="gemma3-27b",
    contents=[
        {"role": "user",  "parts": [{"text": "My name is Alex."}]},
        {"role": "model", "parts": [{"text": "Nice to meet you, Alex!"}]},
        {"role": "user",  "parts": [{"text": "What's my name?"}]},
    ],
)
print(response.text)   # "Your name is Alex."

System instruction

response = client.models.generate_content(
    model="gemma3-27b",
    contents="Tell me a joke.",
    system_instruction="You are a dry, deadpan comedian. Keep it under 2 sentences.",
)
print(response.text)

Generation config

response = client.models.generate_content(
    model="gemma3-27b",
    contents="Write a product description for a smart water bottle.",
    generation_config={
        "temperature": 0.8,
        "max_output_tokens": 256,
        "top_p": 0.95,
    },
)
print(response.text)

Streaming

for chunk in client.models.generate_content_stream(
    model="gemma3-27b",
    contents="Write a short story about a robot who learns to paint.",
):
    print(chunk.text, end="", flush=True)
    if chunk.is_final:
        print()   # newline after stream ends

Embeddings

result = client.models.embed_content(
    model="nomic-embed-text",
    contents="The quick brown fox jumps over the lazy dog",
    task_type="RETRIEVAL_DOCUMENT",
)
vector = result.embedding.values   # List[float]
print(f"Embedding dim: {len(vector)}")

List available models

for model in client.models.list():
    print(model["name"], model.get("displayName", ""))

Custom endpoint (GCP deployment)

When you deploy your own model on Google Cloud Run or Vertex AI:

client = VitaAI(
    api_key="your-key",
    base_url="https://your-cloud-run-service-xyz.a.run.app",
)

Or set the env var:

export VITAAI_BASE_URL="https://your-cloud-run-service-xyz.a.run.app"
export VITAAI_API_KEY="your-key"

Migration from Google Gemini

Before (google.genai) After (vitaai)
from google import genai from vitaai import VitaAI
client = genai.Client() client = VitaAI()
client.models.generate_content(...) client.models.generate_content(...)
response.text response.text ✅ same
response.usage_metadata response.usage_metadata ✅ same

Expected endpoint contract

Your self-hosted backend must expose these routes:

Method Path Purpose
POST /v1/models/generate Text generation
POST /v1/models/generate (stream: true) Streaming
POST /v1/models/embed Embeddings
GET /v1/models/list List models

See docs/endpoint-spec.md for the full request/response schema.


Environment variables

Variable Description
VITAAI_API_KEY API key (alternative to passing api_key=)
VITAAI_BASE_URL Override base URL

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

vitaai-0.2.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

vitaai-0.2.0-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file vitaai-0.2.0.tar.gz.

File metadata

  • Download URL: vitaai-0.2.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for vitaai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 233ed7a0b6015f98063648cb0c33a9d7feec79aa5f046df3fc478922ba085c17
MD5 3e0415e3dbd4a8d4df30a33f4c5ce754
BLAKE2b-256 cd30013912b2eb8c7fd25b411032097738efc2f823a074696dea20ed30aced28

See more details on using hashes here.

File details

Details for the file vitaai-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: vitaai-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for vitaai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a3eabfc6126aa671a77aedb8cb21a92d66f59ec4055b2cba312b19506107dad
MD5 a4c14c21e753c83ba0ec3f5363e8959a
BLAKE2b-256 31aa530c46e60e1e37783be8cdf8a2839d43d1df30c91e6d8eaa41f5af32c7f0

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