[](https://badge.fury.io/py/gravixlayer)
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/Apache-2.0)
The official Python SDK for the [GravixLayer API](https://gravixlayer.com). This library provides convenient access to the GravixLayer REST API from any Python 3.7+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).
## Installation
### PyPI
```bash
pip install gravixlayer
```
### Development Installation
For development or to use the latest features:
```bash
git clone ""https://github.com/gravixlayer/gravixlayer-python"
cd gravixlayer-python
pip install -e .
```
This installs the package in editable mode and makes the `gravixlayer` CLI command available globally.
## Quick Start
The GravixLayer Python SDK is designed to be compatible with OpenAI's interface, making it easy to switch between providers.
### Synchronous Usage
```python
import os
from gravixlayer import GravixLayer
client = GravixLayer(api_key=os.environ.get("GRAVIXLAYER_API_KEY"))
completion = client.chat.completions.create(
model="mistralai/mistral-nemo-instruct-2407",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What are the three most popular programming languages?"}
]
)
print(completion.choices[0].message.content)
```
### Asynchronous Usage
```python
import asyncio
import os
from gravixlayer import AsyncGravixLayer
async def main():
client = AsyncGravixLayer(api_key=os.environ.get("GRAVIXLAYER_API_KEY"))
completion = await client.chat.completions.create(
model="mistralai/mistral-nemo-instruct-2407",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What's the capital of France?"}
]
)
print(completion.choices[0].message.content)
asyncio.run(main())
```
## API Reference
### Chat Completions
Create chat completions with various models available on GravixLayer.
```python
completion = client.chat.completions.create(
model="mistralai/mistral-nemo-instruct-2407",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Tell me a fun fact about space"}
],
temperature=0.7,
max_tokens=150,
top_p=1.0,
frequency_penalty=0,
presence_penalty=0,
stop=None,
stream=False
)
print(completion.choices[0].message.content)
```
#### Available Parameters
| Parameter | Type | Description |
| ------------------- | ------------------ | ------------------------------------ |
| `model` | `str` | Model to use for completion |
| `messages` | `List[Dict]` | List of messages in the conversation |
| `temperature` | `float` | Controls randomness (0.0 to 2.0) |
| `max_tokens` | `int` | Maximum number of tokens to generate |
| `top_p` | `float` | Nucleus sampling parameter |
| `frequency_penalty` | `float` | Penalty for frequent tokens |
| `presence_penalty` | `float` | Penalty for present tokens |
| `stop` | `str \| List[str]` | Stop sequences |
| `stream` | `bool` | Enable streaming responses |
### Streaming Responses
Stream responses in real-time for a better user experience:
```python
stream = client.chat.completions.create(
model="mistralai/mistral-nemo-instruct-2407",
messages=[
{"role": "user", "content": "Tell me about the Eiffel Tower"}
],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="", flush=True)
```
#### Async Streaming
```python
async def stream_chat():
client = AsyncGravixLayer(api_key="your_api_key")
stream = client.chat.completions.create(
model="mistralai/mistral-nemo-instruct-2407",
messages=[{"role": "user", "content": "Tell me about Python"}],
stream=True
)
async for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
```
### Text Completions
Create text completions using the completions endpoint:
```python
completion = client.completions.create(
model="mistralai/mistral-nemo-instruct-2407",
prompt="What are the three most popular programming languages?",
max_tokens=150,
temperature=0.7,
top_p=1.0,
frequency_penalty=0,
presence_penalty=0,
stop=None
)
print(completion.choices[0].text)
```
#### Streaming Text Completions
```python
stream = client.completions.create(
model="mistralai/mistral-nemo-instruct-2407",
prompt="Write a short story about a robot",
max_tokens=200,
temperature=0.8,
stream=True
)
for chunk in stream:
if chunk.choices[0].text:
print(chunk.choices[0].text, end="", flush=True)
```
#### Available Parameters for Completions
| Parameter | Type | Description |
| ------------------- | ------------------ | ----------------------------------------- |
| `model` | `str` | Model to use for completion |
| `prompt` | `str \| List[str]` | The prompt(s) to generate completions for |
| `max_tokens` | `int` | Maximum number of tokens to generate |
| `temperature` | `float` | Controls randomness (0.0 to 2.0) |
| `top_p` | `float` | Nucleus sampling parameter |
| `n` | `int` | Number of completions to generate |
| `stream` | `bool` | Enable streaming responses |
| `logprobs` | `int` | Include log probabilities |
| `echo` | `bool` | Echo back the prompt |
| `stop` | `str \| List[str]` | Stop sequences |
| `presence_penalty` | `float` | Penalty for present tokens |
| `frequency_penalty` | `float` | Penalty for frequent tokens |
### File Management
The GravixLayer SDK provides comprehensive file management capabilities, allowing you to upload, list, retrieve, delete, and access file content. This is useful for managing documents, datasets, and other files that can be used with AI models.
#### Upload Files
Upload files to your GravixLayer account:
```python
# Upload a file
with open("document.pdf", "rb") as file:
upload_response = client.files.upload(
file=file,
purpose="assistants" # or "fine-tune", "batch", etc.
)
print(f"File uploaded: {upload_response.id}")
print(f"Filename: {upload_response.filename}")
print(f"Size: {upload_response.bytes} bytes")
```
#### List Files
Retrieve a list of all uploaded files:
```python
# List all files
files_response = client.files.list()
for file in files_response.data:
print(f"ID: {file.id}")
print(f"Filename: {file.filename}")
print(f"Size: {file.bytes} bytes")
print(f"Created: {file.created_at}")
print(f"Purpose: {file.purpose}")
print("---")
```
#### Retrieve File Information
Get detailed information about a specific file:
```python
# Get file info by ID
file_info = client.files.retrieve("file-abc123")
print(f"Filename: {file_info.filename}")
print(f"Size: {file_info.bytes} bytes")
print(f"Purpose: {file_info.purpose}")
print(f"Created: {file_info.created_at}")
```
#### Download File Content
Retrieve the actual content of a file:
```python
# Download file content
content = client.files.content("file-abc123")
# Save to local file
with open("downloaded_file.pdf", "wb") as f:
f.write(content)
print("File downloaded successfully")
```
#### Delete Files
Remove files from your account:
```python
# Delete a file
delete_response = client.files.delete("file-abc123")
print(f"File deleted: {delete_response.file_name}")
print(f"Message: {delete_response.message}")
```
#### Asynchronous File Operations
All file operations are also available in async mode:
```python
import asyncio
from gravixlayer import AsyncGravixLayer
async def manage_files():
client = AsyncGravixLayer(api_key="your_api_key")
# Upload file
with open("document.pdf", "rb") as file:
upload_response = await client.files.upload(
file=file,
purpose="assistants"
)
# List files
files_response = await client.files.list()
# Get file content
content = await client.files.content(upload_response.id)
# Delete file
delete_response = await client.files.delete(upload_response.id)
print(f"Managed file: {upload_response.filename}")
asyncio.run(manage_files())
```
#### File Management CLI
The SDK includes CLI commands for file management:
```bash
# Upload a file with basic options
gravixlayer files upload document.pdf --purpose assistants
# Upload a file with custom name and expiration
gravixlayer files upload document.pdf --purpose assistants --file_name "my_document.pdf" --expires-after 86400
# Upload for different purposes
gravixlayer files upload dataset.jsonl --purpose fine-tune
gravixlayer files upload image.png --purpose vision
gravixlayer files upload batch_data.csv --purpose batch
gravixlayer files upload eval_data.json --purpose evals
gravixlayer files upload user_file.txt --purpose user_data
# List all files
gravixlayer files list
# List files with JSON output
gravixlayer files list --json
# Get file information (by ID or filename)
gravixlayer files info file-abc123
gravixlayer files info document.pdf
# Download file content (by ID or filename)
gravixlayer files download file-abc123 --output downloaded.pdf
gravixlayer files download document.pdf --output copy.pdf
# Delete a file (by ID or filename)
gravixlayer files delete file-abc123
gravixlayer files delete document.pdf
```
**Upload Command Options:**
- `--file` (required): Path to the file to upload
- `--purpose` (required): File purpose (`assistants`, `fine-tune`, `batch`, `batch_output`, `vision`, `user_data`, `evals`)
- `--file_name` (optional): Custom name for the uploaded file
- `--expires-after` (optional): File expiration time in seconds
- `--api-key` (optional): API key (can also use GRAVIXLAYER_API_KEY environment variable)
#### File Types and Purposes
Supported file purposes:
- `assistants` - Files for use with AI assistants
- `fine-tune` - Files for fine-tuning models
- `batch` - Files for batch processing
- `batch_output` - Output files from batch processing
- `vision` - Image files for vision models
- `user_data` - General user data files
- `evals` - Files for model evaluations
Supported file formats include:
- Documents: PDF, TXT, DOCX, MD
- Images: PNG, JPG, JPEG, GIF, WEBP
- Data: JSON, CSV, JSONL
- Code: PY, JS, HTML, CSS, and more
#### Error Handling for File Operations
```python
from gravixlayer.types.exceptions import (
GravixLayerError,
GravixLayerBadRequestError
)
try:
# Upload file
with open("large_file.pdf", "rb") as file:
upload_response = client.files.upload(file=file, purpose="assistants")
except GravixLayerBadRequestError as e:
if "file too large" in str(e).lower():
print("File is too large. Maximum size is 512MB.")
else:
print(f"Upload failed: {e}")
except FileNotFoundError:
print("File not found. Please check the file path.")
except GravixLayerError as e:
print(f"API error: {e}")
```
### Vector Database
The GravixLayer SDK provides comprehensive vector database capabilities for storing, searching, and managing high-dimensional vectors with text-to-vector conversion.
#### Create and Manage Indexes
```python
# Create a vector index
index = client.vectors.indexes.create(
name="product-embeddings",
dimension=1536,
metric="cosine",
metadata={
"description": "Product description embeddings",
"model": "microsoft/multilingual-e5-large"
}
)
# List all indexes
indexes = client.vectors.indexes.list()
for idx in indexes.indexes:
print(f"Index: {idx.name} (ID: {idx.id})")
# Get index information
index_info = client.vectors.indexes.get(index.id)
```
#### Vector Operations
```python
# Get vector operations for an index
vectors = client.vectors.index(index.id)
# Upsert vectors with embeddings
vector = vectors.upsert(
embedding=[0.1, 0.2, 0.3, ...], # Your embedding
id="product-1",
metadata={
"title": "Wireless Headphones",
"category": "electronics",
"price": 99.99
}
)
# Upsert vectors from text (automatic embedding)
text_vector = vectors.upsert_text(
text="Premium wireless bluetooth headphones with noise cancellation",
model="microsoft/multilingual-e5-large",
id="product-2",
metadata={
"title": "Premium Headphones",
"category": "electronics"
}
)
# Batch operations
batch_vectors = [
{
"id": "product-3",
"embedding": [0.4, 0.5, 0.6, ...],
"metadata": {"title": "Running Shoes"}
},
{
"id": "product-4",
"embedding": [0.7, 0.8, 0.9, ...],
"metadata": {"title": "Sports Watch"}
}
]
batch_result = vectors.batch_upsert(batch_vectors)
```
#### Search Operations
```python
# Vector similarity search
search_results = vectors.search(
vector=[0.15, 0.25, 0.35, ...], # Query vector
top_k=5,
filter={"category": "electronics"}, # Optional metadata filter
include_metadata=True
)
for hit in search_results.hits:
print(f"Product: {hit.metadata['title']} (Score: {hit.score:.4f})")
# Text-based search
text_results = vectors.search_text(
query="bluetooth headphones",
model="microsoft/multilingual-e5-large",
top_k=3,
include_metadata=True
)
print(f"Search completed in {text_results.query_time_ms}ms")
for hit in text_results.hits:
print(f"Match: {hit.metadata['title']} (Score: {hit.score:.4f})")
```
#### Async Vector Operations
```python
import asyncio
from gravixlayer import AsyncGravixLayer
async def vector_operations():
client = AsyncGravixLayer()
# Create index
index = await client.vectors.indexes.create(
name="async-embeddings",
dimension=768,
metric="cosine"
)
# Get vector operations
vectors = client.vectors.index(index.id)
# Concurrent operations
tasks = []
for i in range(5):
task = vectors.upsert_text(
text=f"Document {i} content",
model="microsoft/multilingual-e5-large",
id=f"doc-{i}"
)
tasks.append(task)
# Execute concurrently
results = await asyncio.gather(*tasks)
print(f"Upserted {len(results)} vectors concurrently")
# Concurrent searches
search_tasks = [
vectors.search_text("document", "microsoft/multilingual-e5-large", 3),
vectors.search_text("content", "microsoft/multilingual-e5-large", 3)
]
search_results = await asyncio.gather(*search_tasks)
for i, results in enumerate(search_results):
print(f"Query {i+1}: {len(results.hits)} results")
asyncio.run(vector_operations())
```
### Command Line Interface
The SDK includes a comprehensive CLI for quick testing and vector database management:
#### Chat and Completions
```bash
# Basic chat completion
gravixlayer --model "mistralai/mistral-nemo-instruct-2407" --user "Hello, how are you?"
# Streaming chat response
gravixlayer --model "mistralai/mistral-nemo-instruct-2407" --user "Tell me a story" --stream
# Text completion mode
gravixlayer --mode completions --model "meta-llama/llama-3.1-8b-instruct" --prompt "The future of AI is"
# Streaming text completion
gravixlayer --mode completions --model "meta-llama/llama-3.1-8b-instruct" --prompt "Write a poem about" --stream
# With system message
gravixlayer --model "mistralai/mistral-nemo-instruct-2407" --system "You are a poet" --user "Write a haiku"
```
### Deployment Management
The CLI supports deployment management using the `deployments` command:
```bash
# Create a deployment with all parameters
gravixlayer deployments create \
--deployment_name "my-model-deployment" \
--model_name "mistralai/mistral-nemo-instruct-2407" \
--gpu_model "NVIDIA_T4_16GB" \
--gpu_count 1 \
--min_replicas 1 \
--max_replicas 1 \
--hw_type "dedicated"
# Create deployment with auto-retry (generates unique name if exists)
gravixlayer deployments create \
--deployment_name "my-model" \
--model_name "qwen3-1.7b" \
--gpu_model "NVIDIA_T4_16GB" \
--gpu_count 2 \
--auto-retry
# Create deployment and wait for it to be ready
gravixlayer deployments create \
--deployment_name "production-model" \
--model_name "meta-llama/llama-3.1-8b-instruct" \
--gpu_model "NVIDIA_A100_80GB" \
--gpu_count 4 \
--wait
# List all deployments
gravixlayer deployments list
# List deployments as JSON
gravixlayer deployments list --json
# Delete a deployment
gravixlayer deployments delete <deployment_id>
# List available GPUs/hardware
gravixlayer deployments gpu --list
# List available hardware (same as gpu)
gravixlayer deployments hardware --list
# List GPUs as JSON
gravixlayer deployments gpu --list --json
```
#### Deployment Create Parameters
| Parameter | Type | Required | Description |
| ------------------- | ------ | -------- | ---------------------------------------------- |
| `--deployment_name` | `str` | Yes | Unique name for the deployment |
| `--model_name` | `str` | Yes | Model name to deploy |
| `--gpu_model` | `str` | Yes | GPU model (e.g., NVIDIA_T4_16GB) |
| `--gpu_count` | `int` | No | Number of GPUs (supported: 1, 2, 4, 8) |
| `--min_replicas` | `int` | No | Minimum replicas (default: 1) |
| `--max_replicas` | `int` | No | Maximum replicas (default: 1) |
| `--hw_type` | `str` | No | Hardware type (default: dedicated) |
| `--auto-retry` | `flag` | No | Auto-retry with unique name if name exists |
| `--wait` | `flag` | No | Wait for deployment to be ready before exiting |
#### GPU Count Validation
The `--gpu_count` parameter only accepts the following values: **1, 2, 4, 8**
If you provide any other value, you'll receive an error:
```bash
❌ Error: GPU count must be one of: 1, 2, 4, 8. You provided: 3
Only these GPU counts are supported.
```
#### Auto-Retry Feature
Use the `--auto-retry` flag to automatically generate a unique deployment name if the specified name already exists:
```bash
gravixlayer deployments create \
--deployment_name "my-model" \
--model_name "qwen3-1.7b" \
--gpu_model "NVIDIA_T4_16GB" \
--auto-retry
```
This will create a deployment with a name like `my-model-1234abcd` if `my-model` already exists.
#### Wait for Deployment
Use the `--wait` flag to monitor deployment status and wait until it's ready:
```bash
gravixlayer deployments create \
--deployment_name "production-model" \
--model_name "mistralai/mistral-nemo-instruct-2407" \
--gpu_model "NVIDIA_A100_80GB" \
--wait
```
This will show real-time status updates until the deployment is ready to use.
#### GPU/Hardware Listing
You can list all available GPUs and hardware configurations:
```bash
# List available GPUs in table format
gravixlayer deployments gpu --list
# List available hardware (alias for gpu)
gravixlayer deployments hardware --list
# Get detailed information in JSON format
gravixlayer deployments gpu --list --json
```
#### Vector Database CLI
```bash
# Create a vector index
gravixlayer vectors index create \
--name "product-embeddings" \
--dimension 1536 \
--metric cosine \
--cloud-provider AWS \
--region us-east-1 \
--index-type serverless \
--metadata '{"description": "Product embeddings"}'
# List all indexes
gravixlayer vectors index list
# Upsert a text vector
gravixlayer vectors vector upsert-text <index-id> \
--text "Wireless bluetooth headphones" \
--model "microsoft/multilingual-e5-large" \
--id "product-1" \
--metadata '{"category": "electronics"}'
# Search using text
gravixlayer vectors vector search-text <index-id> \
--query "headphones" \
--model "microsoft/multilingual-e5-large" \
--top-k 5
# Search using vector
gravixlayer vectors vector search <index-id> \
--vector '[0.1, 0.2, 0.3, ...]' \
--top-k 5 \
--filter '{"category": "electronics"}'
# List vectors in index
gravixlayer vectors vector list <index-id>
# Get vector information
gravixlayer vectors vector get <index-id> <vector-id>
# Delete vector
gravixlayer vectors vector delete <index-id> <vector-id>
# Delete index
gravixlayer vectors index delete <index-id>
```
## Configuration
### API Key
Set your API key using environment variables:
#### Set API key (Linux/macOS)
```bash
export GRAVIXLAYER_API_KEY="your_api_key_here"
```
or
#### Set API key (Windows PowerShell)
```bash
$env:GRAVIXLAYER_API_KEY="your_api_key_here"
```
Or pass it directly when initializing the client:
```python
client = GravixLayer(api_key="your_api_key_here")
```
## License
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.
## Changelog
See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes.
Raw data
{
"_id": null,
"home_page": "https://github.com/gravixlayer/gravixlayer-python",
"name": "gravixlayer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "gravixlayer, llm, ai, api, sdk, compatible",
"author": "Team Gravix",
"author_email": "Team Gravix <info@gravixlayer.com>",
"download_url": "https://files.pythonhosted.org/packages/03/fc/4ee0abe36aa630079d1315f74701dc5b085c808c3c45e0915ca9ddcfdc42/gravixlayer-0.0.40.tar.gz",
"platform": null,
"description": "\n[](https://badge.fury.io/py/gravixlayer)\n[](https://www.python.org/downloads/)\n[](https://opensource.org/licenses/Apache-2.0)\n\nThe official Python SDK for the [GravixLayer API](https://gravixlayer.com). This library provides convenient access to the GravixLayer REST API from any Python 3.7+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by [httpx](https://github.com/encode/httpx).\n\n\n## Installation\n\n### PyPI\n\n```bash\npip install gravixlayer\n```\n\n### Development Installation\n\nFor development or to use the latest features:\n\n```bash\ngit clone \"\"https://github.com/gravixlayer/gravixlayer-python\"\ncd gravixlayer-python\npip install -e .\n```\n\nThis installs the package in editable mode and makes the `gravixlayer` CLI command available globally.\n\n## Quick Start\n\nThe GravixLayer Python SDK is designed to be compatible with OpenAI's interface, making it easy to switch between providers.\n\n### Synchronous Usage\n\n```python\nimport os\nfrom gravixlayer import GravixLayer\n\nclient = GravixLayer(api_key=os.environ.get(\"GRAVIXLAYER_API_KEY\"))\n\ncompletion = client.chat.completions.create(\n model=\"mistralai/mistral-nemo-instruct-2407\",\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n {\"role\": \"user\", \"content\": \"What are the three most popular programming languages?\"}\n ]\n)\n\nprint(completion.choices[0].message.content)\n```\n\n### Asynchronous Usage\n\n```python\nimport asyncio\nimport os\nfrom gravixlayer import AsyncGravixLayer\n\nasync def main():\n client = AsyncGravixLayer(api_key=os.environ.get(\"GRAVIXLAYER_API_KEY\"))\n \n completion = await client.chat.completions.create(\n model=\"mistralai/mistral-nemo-instruct-2407\",\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n {\"role\": \"user\", \"content\": \"What's the capital of France?\"}\n ]\n )\n \n print(completion.choices[0].message.content)\n\nasyncio.run(main())\n```\n\n## API Reference\n\n### Chat Completions\n\nCreate chat completions with various models available on GravixLayer.\n\n```python\ncompletion = client.chat.completions.create(\n model=\"mistralai/mistral-nemo-instruct-2407\",\n messages=[\n {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n {\"role\": \"user\", \"content\": \"Tell me a fun fact about space\"}\n ],\n temperature=0.7,\n max_tokens=150,\n top_p=1.0,\n frequency_penalty=0,\n presence_penalty=0,\n stop=None,\n stream=False\n)\n\nprint(completion.choices[0].message.content)\n```\n\n#### Available Parameters\n\n| Parameter | Type | Description |\n| ------------------- | ------------------ | ------------------------------------ |\n| `model` | `str` | Model to use for completion |\n| `messages` | `List[Dict]` | List of messages in the conversation |\n| `temperature` | `float` | Controls randomness (0.0 to 2.0) |\n| `max_tokens` | `int` | Maximum number of tokens to generate |\n| `top_p` | `float` | Nucleus sampling parameter |\n| `frequency_penalty` | `float` | Penalty for frequent tokens |\n| `presence_penalty` | `float` | Penalty for present tokens |\n| `stop` | `str \\| List[str]` | Stop sequences |\n| `stream` | `bool` | Enable streaming responses |\n\n### Streaming Responses\n\nStream responses in real-time for a better user experience:\n\n```python\nstream = client.chat.completions.create(\n model=\"mistralai/mistral-nemo-instruct-2407\",\n messages=[\n {\"role\": \"user\", \"content\": \"Tell me about the Eiffel Tower\"}\n ],\n stream=True\n)\n\nfor chunk in stream:\n if chunk.choices[0].delta.content is not None:\n print(chunk.choices[0].delta.content, end=\"\", flush=True)\n```\n\n#### Async Streaming\n\n```python\nasync def stream_chat():\n client = AsyncGravixLayer(api_key=\"your_api_key\")\n \n stream = client.chat.completions.create(\n model=\"mistralai/mistral-nemo-instruct-2407\",\n messages=[{\"role\": \"user\", \"content\": \"Tell me about Python\"}],\n stream=True\n )\n \n async for chunk in stream:\n if chunk.choices[0].delta.content:\n print(chunk.choices[0].delta.content, end=\"\", flush=True)\n```\n\n\n\n### Text Completions\n\nCreate text completions using the completions endpoint:\n\n```python\ncompletion = client.completions.create(\n model=\"mistralai/mistral-nemo-instruct-2407\",\n prompt=\"What are the three most popular programming languages?\",\n max_tokens=150,\n temperature=0.7,\n top_p=1.0,\n frequency_penalty=0,\n presence_penalty=0,\n stop=None\n)\n\nprint(completion.choices[0].text)\n```\n\n#### Streaming Text Completions\n\n```python\nstream = client.completions.create(\n model=\"mistralai/mistral-nemo-instruct-2407\",\n prompt=\"Write a short story about a robot\",\n max_tokens=200,\n temperature=0.8,\n stream=True\n)\n\nfor chunk in stream:\n if chunk.choices[0].text:\n print(chunk.choices[0].text, end=\"\", flush=True)\n```\n\n#### Available Parameters for Completions\n\n| Parameter | Type | Description |\n| ------------------- | ------------------ | ----------------------------------------- |\n| `model` | `str` | Model to use for completion |\n| `prompt` | `str \\| List[str]` | The prompt(s) to generate completions for |\n| `max_tokens` | `int` | Maximum number of tokens to generate |\n| `temperature` | `float` | Controls randomness (0.0 to 2.0) |\n| `top_p` | `float` | Nucleus sampling parameter |\n| `n` | `int` | Number of completions to generate |\n| `stream` | `bool` | Enable streaming responses |\n| `logprobs` | `int` | Include log probabilities |\n| `echo` | `bool` | Echo back the prompt |\n| `stop` | `str \\| List[str]` | Stop sequences |\n| `presence_penalty` | `float` | Penalty for present tokens |\n| `frequency_penalty` | `float` | Penalty for frequent tokens |\n\n\n### File Management\n\nThe GravixLayer SDK provides comprehensive file management capabilities, allowing you to upload, list, retrieve, delete, and access file content. This is useful for managing documents, datasets, and other files that can be used with AI models.\n\n#### Upload Files\n\nUpload files to your GravixLayer account:\n\n```python\n# Upload a file\nwith open(\"document.pdf\", \"rb\") as file:\n upload_response = client.files.upload(\n file=file,\n purpose=\"assistants\" # or \"fine-tune\", \"batch\", etc.\n )\n \nprint(f\"File uploaded: {upload_response.id}\")\nprint(f\"Filename: {upload_response.filename}\")\nprint(f\"Size: {upload_response.bytes} bytes\")\n```\n\n#### List Files\n\nRetrieve a list of all uploaded files:\n\n```python\n# List all files\nfiles_response = client.files.list()\n\nfor file in files_response.data:\n print(f\"ID: {file.id}\")\n print(f\"Filename: {file.filename}\")\n print(f\"Size: {file.bytes} bytes\")\n print(f\"Created: {file.created_at}\")\n print(f\"Purpose: {file.purpose}\")\n print(\"---\")\n```\n\n#### Retrieve File Information\n\nGet detailed information about a specific file:\n\n```python\n# Get file info by ID\nfile_info = client.files.retrieve(\"file-abc123\")\n\nprint(f\"Filename: {file_info.filename}\")\nprint(f\"Size: {file_info.bytes} bytes\")\nprint(f\"Purpose: {file_info.purpose}\")\nprint(f\"Created: {file_info.created_at}\")\n```\n\n#### Download File Content\n\nRetrieve the actual content of a file:\n\n```python\n# Download file content\ncontent = client.files.content(\"file-abc123\")\n\n# Save to local file\nwith open(\"downloaded_file.pdf\", \"wb\") as f:\n f.write(content)\n\nprint(\"File downloaded successfully\")\n```\n\n#### Delete Files\n\nRemove files from your account:\n\n```python\n# Delete a file\ndelete_response = client.files.delete(\"file-abc123\")\n\nprint(f\"File deleted: {delete_response.file_name}\")\nprint(f\"Message: {delete_response.message}\")\n```\n\n#### Asynchronous File Operations\n\nAll file operations are also available in async mode:\n\n```python\nimport asyncio\nfrom gravixlayer import AsyncGravixLayer\n\nasync def manage_files():\n client = AsyncGravixLayer(api_key=\"your_api_key\")\n \n # Upload file\n with open(\"document.pdf\", \"rb\") as file:\n upload_response = await client.files.upload(\n file=file,\n purpose=\"assistants\"\n )\n \n # List files\n files_response = await client.files.list()\n \n # Get file content\n content = await client.files.content(upload_response.id)\n \n # Delete file\n delete_response = await client.files.delete(upload_response.id)\n \n print(f\"Managed file: {upload_response.filename}\")\n\nasyncio.run(manage_files())\n```\n\n#### File Management CLI\n\nThe SDK includes CLI commands for file management:\n\n```bash\n# Upload a file with basic options\ngravixlayer files upload document.pdf --purpose assistants\n\n# Upload a file with custom name and expiration\ngravixlayer files upload document.pdf --purpose assistants --file_name \"my_document.pdf\" --expires-after 86400\n\n# Upload for different purposes\ngravixlayer files upload dataset.jsonl --purpose fine-tune\ngravixlayer files upload image.png --purpose vision\ngravixlayer files upload batch_data.csv --purpose batch\ngravixlayer files upload eval_data.json --purpose evals\ngravixlayer files upload user_file.txt --purpose user_data\n\n# List all files\ngravixlayer files list\n\n# List files with JSON output\ngravixlayer files list --json\n\n# Get file information (by ID or filename)\ngravixlayer files info file-abc123\ngravixlayer files info document.pdf\n\n# Download file content (by ID or filename)\ngravixlayer files download file-abc123 --output downloaded.pdf\ngravixlayer files download document.pdf --output copy.pdf\n\n# Delete a file (by ID or filename)\ngravixlayer files delete file-abc123\ngravixlayer files delete document.pdf\n```\n\n**Upload Command Options:**\n- `--file` (required): Path to the file to upload\n- `--purpose` (required): File purpose (`assistants`, `fine-tune`, `batch`, `batch_output`, `vision`, `user_data`, `evals`)\n- `--file_name` (optional): Custom name for the uploaded file\n- `--expires-after` (optional): File expiration time in seconds\n- `--api-key` (optional): API key (can also use GRAVIXLAYER_API_KEY environment variable)\n\n#### File Types and Purposes\n\nSupported file purposes:\n- `assistants` - Files for use with AI assistants\n- `fine-tune` - Files for fine-tuning models\n- `batch` - Files for batch processing\n- `batch_output` - Output files from batch processing\n- `vision` - Image files for vision models\n- `user_data` - General user data files\n- `evals` - Files for model evaluations\n\nSupported file formats include:\n- Documents: PDF, TXT, DOCX, MD\n- Images: PNG, JPG, JPEG, GIF, WEBP\n- Data: JSON, CSV, JSONL\n- Code: PY, JS, HTML, CSS, and more\n\n#### Error Handling for File Operations\n\n```python\nfrom gravixlayer.types.exceptions import (\n GravixLayerError,\n GravixLayerBadRequestError\n)\n\ntry:\n # Upload file\n with open(\"large_file.pdf\", \"rb\") as file:\n upload_response = client.files.upload(file=file, purpose=\"assistants\")\nexcept GravixLayerBadRequestError as e:\n if \"file too large\" in str(e).lower():\n print(\"File is too large. Maximum size is 512MB.\")\n else:\n print(f\"Upload failed: {e}\")\nexcept FileNotFoundError:\n print(\"File not found. Please check the file path.\")\nexcept GravixLayerError as e:\n print(f\"API error: {e}\")\n```\n\n\n### Vector Database\n\nThe GravixLayer SDK provides comprehensive vector database capabilities for storing, searching, and managing high-dimensional vectors with text-to-vector conversion.\n\n#### Create and Manage Indexes\n\n```python\n# Create a vector index\nindex = client.vectors.indexes.create(\n name=\"product-embeddings\",\n dimension=1536,\n metric=\"cosine\",\n metadata={\n \"description\": \"Product description embeddings\",\n \"model\": \"microsoft/multilingual-e5-large\"\n }\n)\n\n# List all indexes\nindexes = client.vectors.indexes.list()\nfor idx in indexes.indexes:\n print(f\"Index: {idx.name} (ID: {idx.id})\")\n\n# Get index information\nindex_info = client.vectors.indexes.get(index.id)\n```\n\n#### Vector Operations\n\n```python\n# Get vector operations for an index\nvectors = client.vectors.index(index.id)\n\n# Upsert vectors with embeddings\nvector = vectors.upsert(\n embedding=[0.1, 0.2, 0.3, ...], # Your embedding\n id=\"product-1\",\n metadata={\n \"title\": \"Wireless Headphones\",\n \"category\": \"electronics\",\n \"price\": 99.99\n }\n)\n\n# Upsert vectors from text (automatic embedding)\ntext_vector = vectors.upsert_text(\n text=\"Premium wireless bluetooth headphones with noise cancellation\",\n model=\"microsoft/multilingual-e5-large\",\n id=\"product-2\",\n metadata={\n \"title\": \"Premium Headphones\",\n \"category\": \"electronics\"\n }\n)\n\n# Batch operations\nbatch_vectors = [\n {\n \"id\": \"product-3\",\n \"embedding\": [0.4, 0.5, 0.6, ...],\n \"metadata\": {\"title\": \"Running Shoes\"}\n },\n {\n \"id\": \"product-4\", \n \"embedding\": [0.7, 0.8, 0.9, ...],\n \"metadata\": {\"title\": \"Sports Watch\"}\n }\n]\nbatch_result = vectors.batch_upsert(batch_vectors)\n```\n\n#### Search Operations\n\n```python\n# Vector similarity search\nsearch_results = vectors.search(\n vector=[0.15, 0.25, 0.35, ...], # Query vector\n top_k=5,\n filter={\"category\": \"electronics\"}, # Optional metadata filter\n include_metadata=True\n)\n\nfor hit in search_results.hits:\n print(f\"Product: {hit.metadata['title']} (Score: {hit.score:.4f})\")\n\n# Text-based search\ntext_results = vectors.search_text(\n query=\"bluetooth headphones\",\n model=\"microsoft/multilingual-e5-large\",\n top_k=3,\n include_metadata=True\n)\n\nprint(f\"Search completed in {text_results.query_time_ms}ms\")\nfor hit in text_results.hits:\n print(f\"Match: {hit.metadata['title']} (Score: {hit.score:.4f})\")\n```\n\n#### Async Vector Operations\n\n```python\nimport asyncio\nfrom gravixlayer import AsyncGravixLayer\n\nasync def vector_operations():\n client = AsyncGravixLayer()\n \n # Create index\n index = await client.vectors.indexes.create(\n name=\"async-embeddings\",\n dimension=768,\n metric=\"cosine\"\n )\n \n # Get vector operations\n vectors = client.vectors.index(index.id)\n \n # Concurrent operations\n tasks = []\n for i in range(5):\n task = vectors.upsert_text(\n text=f\"Document {i} content\",\n model=\"microsoft/multilingual-e5-large\",\n id=f\"doc-{i}\"\n )\n tasks.append(task)\n \n # Execute concurrently\n results = await asyncio.gather(*tasks)\n print(f\"Upserted {len(results)} vectors concurrently\")\n \n # Concurrent searches\n search_tasks = [\n vectors.search_text(\"document\", \"microsoft/multilingual-e5-large\", 3),\n vectors.search_text(\"content\", \"microsoft/multilingual-e5-large\", 3)\n ]\n \n search_results = await asyncio.gather(*search_tasks)\n for i, results in enumerate(search_results):\n print(f\"Query {i+1}: {len(results.hits)} results\")\n\nasyncio.run(vector_operations())\n```\n\n### Command Line Interface\n\nThe SDK includes a comprehensive CLI for quick testing and vector database management:\n\n#### Chat and Completions\n```bash\n# Basic chat completion\ngravixlayer --model \"mistralai/mistral-nemo-instruct-2407\" --user \"Hello, how are you?\"\n\n# Streaming chat response\ngravixlayer --model \"mistralai/mistral-nemo-instruct-2407\" --user \"Tell me a story\" --stream\n\n# Text completion mode\ngravixlayer --mode completions --model \"meta-llama/llama-3.1-8b-instruct\" --prompt \"The future of AI is\"\n\n# Streaming text completion\ngravixlayer --mode completions --model \"meta-llama/llama-3.1-8b-instruct\" --prompt \"Write a poem about\" --stream\n\n# With system message\ngravixlayer --model \"mistralai/mistral-nemo-instruct-2407\" --system \"You are a poet\" --user \"Write a haiku\"\n```\n\n### Deployment Management\n\nThe CLI supports deployment management using the `deployments` command:\n\n```bash\n# Create a deployment with all parameters\ngravixlayer deployments create \\\n --deployment_name \"my-model-deployment\" \\\n --model_name \"mistralai/mistral-nemo-instruct-2407\" \\\n --gpu_model \"NVIDIA_T4_16GB\" \\\n --gpu_count 1 \\\n --min_replicas 1 \\\n --max_replicas 1 \\\n --hw_type \"dedicated\"\n\n# Create deployment with auto-retry (generates unique name if exists)\ngravixlayer deployments create \\\n --deployment_name \"my-model\" \\\n --model_name \"qwen3-1.7b\" \\\n --gpu_model \"NVIDIA_T4_16GB\" \\\n --gpu_count 2 \\\n --auto-retry\n\n# Create deployment and wait for it to be ready\ngravixlayer deployments create \\\n --deployment_name \"production-model\" \\\n --model_name \"meta-llama/llama-3.1-8b-instruct\" \\\n --gpu_model \"NVIDIA_A100_80GB\" \\\n --gpu_count 4 \\\n --wait\n\n# List all deployments\ngravixlayer deployments list\n\n# List deployments as JSON\ngravixlayer deployments list --json\n\n# Delete a deployment\ngravixlayer deployments delete <deployment_id>\n\n# List available GPUs/hardware\ngravixlayer deployments gpu --list\n\n# List available hardware (same as gpu)\ngravixlayer deployments hardware --list\n\n# List GPUs as JSON\ngravixlayer deployments gpu --list --json\n```\n\n#### Deployment Create Parameters\n\n| Parameter | Type | Required | Description |\n| ------------------- | ------ | -------- | ---------------------------------------------- |\n| `--deployment_name` | `str` | Yes | Unique name for the deployment |\n| `--model_name` | `str` | Yes | Model name to deploy |\n| `--gpu_model` | `str` | Yes | GPU model (e.g., NVIDIA_T4_16GB) |\n| `--gpu_count` | `int` | No | Number of GPUs (supported: 1, 2, 4, 8) |\n| `--min_replicas` | `int` | No | Minimum replicas (default: 1) |\n| `--max_replicas` | `int` | No | Maximum replicas (default: 1) |\n| `--hw_type` | `str` | No | Hardware type (default: dedicated) |\n| `--auto-retry` | `flag` | No | Auto-retry with unique name if name exists |\n| `--wait` | `flag` | No | Wait for deployment to be ready before exiting |\n\n#### GPU Count Validation\n\nThe `--gpu_count` parameter only accepts the following values: **1, 2, 4, 8**\n\nIf you provide any other value, you'll receive an error:\n```bash\n\u274c Error: GPU count must be one of: 1, 2, 4, 8. You provided: 3\nOnly these GPU counts are supported.\n```\n\n#### Auto-Retry Feature\n\nUse the `--auto-retry` flag to automatically generate a unique deployment name if the specified name already exists:\n\n```bash\ngravixlayer deployments create \\\n --deployment_name \"my-model\" \\\n --model_name \"qwen3-1.7b\" \\\n --gpu_model \"NVIDIA_T4_16GB\" \\\n --auto-retry\n```\n\nThis will create a deployment with a name like `my-model-1234abcd` if `my-model` already exists.\n\n#### Wait for Deployment\n\nUse the `--wait` flag to monitor deployment status and wait until it's ready:\n\n```bash\ngravixlayer deployments create \\\n --deployment_name \"production-model\" \\\n --model_name \"mistralai/mistral-nemo-instruct-2407\" \\\n --gpu_model \"NVIDIA_A100_80GB\" \\\n --wait\n```\n\nThis will show real-time status updates until the deployment is ready to use.\n\n#### GPU/Hardware Listing\n\nYou can list all available GPUs and hardware configurations:\n\n```bash\n# List available GPUs in table format\ngravixlayer deployments gpu --list\n\n# List available hardware (alias for gpu)\ngravixlayer deployments hardware --list\n\n# Get detailed information in JSON format\ngravixlayer deployments gpu --list --json\n```\n\n#### Vector Database CLI\n\n```bash\n# Create a vector index\ngravixlayer vectors index create \\\n --name \"product-embeddings\" \\\n --dimension 1536 \\\n --metric cosine \\\n --cloud-provider AWS \\\n --region us-east-1 \\\n --index-type serverless \\\n --metadata '{\"description\": \"Product embeddings\"}'\n\n# List all indexes\ngravixlayer vectors index list\n\n# Upsert a text vector\ngravixlayer vectors vector upsert-text <index-id> \\\n --text \"Wireless bluetooth headphones\" \\\n --model \"microsoft/multilingual-e5-large\" \\\n --id \"product-1\" \\\n --metadata '{\"category\": \"electronics\"}'\n\n# Search using text\ngravixlayer vectors vector search-text <index-id> \\\n --query \"headphones\" \\\n --model \"microsoft/multilingual-e5-large\" \\\n --top-k 5\n\n# Search using vector\ngravixlayer vectors vector search <index-id> \\\n --vector '[0.1, 0.2, 0.3, ...]' \\\n --top-k 5 \\\n --filter '{\"category\": \"electronics\"}'\n\n# List vectors in index\ngravixlayer vectors vector list <index-id>\n\n# Get vector information\ngravixlayer vectors vector get <index-id> <vector-id>\n\n# Delete vector\ngravixlayer vectors vector delete <index-id> <vector-id>\n\n# Delete index\ngravixlayer vectors index delete <index-id>\n```\n\n\n## Configuration\n\n### API Key\n\nSet your API key using environment variables:\n\n#### Set API key (Linux/macOS)\n```bash\nexport GRAVIXLAYER_API_KEY=\"your_api_key_here\"\n```\n\nor \n\n#### Set API key (Windows PowerShell)\n```bash\n$env:GRAVIXLAYER_API_KEY=\"your_api_key_here\"\n```\n\nOr pass it directly when initializing the client:\n\n```python\nclient = GravixLayer(api_key=\"your_api_key_here\")\n```\n\n## License\n\nThis project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.\n\n## Changelog\n\nSee [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes.\n\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "GravixLayer Python SDK ",
"version": "0.0.40",
"project_urls": {
"Homepage": "https://github.com/gravixlayer/gravixlayer-python",
"Issues": "https://github.com/gravixlayer/gravixlayer-pythonissues",
"Repository": "https://github.com/gravixlayer/gravixlayer-python"
},
"split_keywords": [
"gravixlayer",
" llm",
" ai",
" api",
" sdk",
" compatible"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "8d1eb3f7e84736dbea389b2ac2fa90c062211813a8540ee5552edc0f7b86efef",
"md5": "3f0cc7a2e136f1cb599787fefaf9cc27",
"sha256": "0ee8c4242db5c521e1a588c668d848a22ba303f99070482be6e199be396b23a9"
},
"downloads": -1,
"filename": "gravixlayer-0.0.40-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3f0cc7a2e136f1cb599787fefaf9cc27",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 119372,
"upload_time": "2025-10-22T09:52:47",
"upload_time_iso_8601": "2025-10-22T09:52:47.840000Z",
"url": "https://files.pythonhosted.org/packages/8d/1e/b3f7e84736dbea389b2ac2fa90c062211813a8540ee5552edc0f7b86efef/gravixlayer-0.0.40-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "03fc4ee0abe36aa630079d1315f74701dc5b085c808c3c45e0915ca9ddcfdc42",
"md5": "cfb8495ab7a3903270c4d7bf94ba070e",
"sha256": "70c173dc353257391cfb435b0eacb9abe2a4d0fd37da51cb936362f01ae46e69"
},
"downloads": -1,
"filename": "gravixlayer-0.0.40.tar.gz",
"has_sig": false,
"md5_digest": "cfb8495ab7a3903270c4d7bf94ba070e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 106028,
"upload_time": "2025-10-22T09:52:49",
"upload_time_iso_8601": "2025-10-22T09:52:49.328496Z",
"url": "https://files.pythonhosted.org/packages/03/fc/4ee0abe36aa630079d1315f74701dc5b085c808c3c45e0915ca9ddcfdc42/gravixlayer-0.0.40.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-22 09:52:49",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gravixlayer",
"github_project": "gravixlayer-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "requests",
"specs": [
[
">=",
"2.25.0"
]
]
},
{
"name": "python-dotenv",
"specs": [
[
">=",
"0.19.0"
]
]
},
{
"name": "httpx",
"specs": [
[
">=",
"0.24.0"
]
]
}
],
"lcname": "gravixlayer"
}