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 |
| POST | /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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vitaai-0.1.0.tar.gz.
File metadata
- Download URL: vitaai-0.1.0.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4048472f9cdce43051c4ad42c55bde477063bb0bf43521ccc36e025aea5daa5
|
|
| MD5 |
b922bcfb2dc27f28774d63541260e87b
|
|
| BLAKE2b-256 |
4755dd8fab3d23f505b82ca0359c75f0689813da5b82bbd1d48e0616082820fa
|
File details
Details for the file vitaai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vitaai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
86e290dc88b1e3cc9633af2b7b0a8f75f94b0d33b6f152e473604b8124b1629a
|
|
| MD5 |
13ed070380b9f828b679fc3566614420
|
|
| BLAKE2b-256 |
8da1ce3462e6dc0773c4b2d27cf4bc76b3626c2e38212b2992546d5b6d52a798
|