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.
Install
pip install vitaai
Quick start
from vitaai import VitaAI
client = VitaAI(
api_key="your-api-key",
base_url="http://your-server-ip:8000"
)
response = client.models.generate_content(
model="gemma-2b-it",
contents="What is AI?",
max_output_tokens=100
)
print(response.text)
print("Tokens used:", response.usage_metadata.total_token_count)
Usage
Generate content
response = client.models.generate_content(
model="gemma-2b-it",
contents="What is the capital of France?",
)
print(response.text)
print(response.usage_metadata.total_token_count)
Control output length
response = client.models.generate_content(
model="gemma-2b-it",
contents="Explain machine learning",
max_output_tokens=200
)
print(response.text)
Generation config
response = client.models.generate_content(
model="gemma-2b-it",
contents="Write a product description",
generation_config={
"temperature": 0.8,
"max_output_tokens": 256,
"top_p": 0.95,
},
)
print(response.text)
System instruction
response = client.models.generate_content(
model="gemma-2b-it",
contents="Tell me a joke.",
system_instruction="You are a dry, deadpan comedian. Keep it under 2 sentences.",
)
print(response.text)
Multi-turn conversation
response = client.models.generate_content(
model="gemma-2b-it",
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)
Streaming
for chunk in client.models.generate_content_stream(
model="gemma-2b-it",
contents="Write a short story",
max_output_tokens=300
):
print(chunk.text, end="", flush=True)
print()
Embeddings
response = client.models.embed_content(
contents="The quick brown fox jumps over the lazy dog"
)
print(len(response.embedding.values)) # number of dimensions e.g. 384
print(response.embedding.values) # list of floats
List available models
for model in client.models.list():
print(model["name"], model.get("displayName", ""))
Error handling
from vitaai.transport import AuthenticationError, RateLimitError, ServerError
try:
response = client.models.generate_content(
model="gemma-2b-it",
contents="Hello"
)
print(response.text)
except AuthenticationError:
print("Invalid API key")
except RateLimitError:
print("Too many requests")
except ServerError:
print("Server error")
except Exception as e:
print(f"Error: {e}")
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 |
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 |
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.3.0.tar.gz
(15.9 kB
view details)
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
vitaai-0.3.0-py3-none-any.whl
(18.5 kB
view details)
File details
Details for the file vitaai-0.3.0.tar.gz.
File metadata
- Download URL: vitaai-0.3.0.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9df79c117535d2f7b6375274eadd28d634355c52481d31bf507a2b1ffdc5826f
|
|
| MD5 |
35f80c281259d4005d682865a5aaa151
|
|
| BLAKE2b-256 |
7274e4e3309de00129c53929fc638cad5167554443c3f8dbfbf63f3dd23ac809
|
File details
Details for the file vitaai-0.3.0-py3-none-any.whl.
File metadata
- Download URL: vitaai-0.3.0-py3-none-any.whl
- Upload date:
- Size: 18.5 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 |
8db7109b6b2850eaa9cfae7741f3d0174c6d137451d250a482f338e11d3a259f
|
|
| MD5 |
a249969d3293a80b917effa395370e90
|
|
| BLAKE2b-256 |
819bc40e67051461359dc07084bdb01aacb6fc543cdd8c00a4215565b02c4b04
|