Skip to content
SolidRusT.ai

SDK Usage Guide

This guide provides complete working examples for integrating the SolidRusT AI API into your applications. Since our API is OpenAI-compatible, you can use the official OpenAI SDKs with a custom base URL.

SettingValue
Base URLhttps://api.solidrust.ai/v1
Chat Modelvllm-primary (Gemma 4 12B IT QAT)
Embeddings ModelQwen/Qwen3-Embedding-0.6B
API Keysconsole.solidrust.ai
Terminal window
pip install openai
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.solidrust.ai/v1"
)

Send a message and receive a complete response.

from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.solidrust.ai/v1"
)
response = client.chat.completions.create(
model="vllm-primary",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of France?"}
]
)
print(response.choices[0].message.content)
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1706124800,
"model": "vllm-primary",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The capital of France is Paris."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 8,
"total_tokens": 33
}
}

Receive tokens as they are generated for a more responsive user experience.

from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.solidrust.ai/v1"
)
stream = client.chat.completions.create(
model="vllm-primary",
messages=[
{"role": "user", "content": "Write a short poem about the ocean."}
],
stream=True
)
for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
print() # Newline at end

Async version:

from openai import AsyncOpenAI
import asyncio
client = AsyncOpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.solidrust.ai/v1"
)
async def stream_response():
stream = await client.chat.completions.create(
model="vllm-primary",
messages=[{"role": "user", "content": "Write a short poem about the ocean."}],
stream=True
)
async for chunk in stream:
content = chunk.choices[0].delta.content
if content:
print(content, end="", flush=True)
asyncio.run(stream_response())

Each chunk arrives as a Server-Sent Event:

data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"The"},"finish_reason":null}]}
data: {"id":"chatcmpl-123","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" ocean"},"finish_reason":null}]}
data: [DONE]

Generate vector embeddings for semantic search, similarity matching, and RAG applications.

from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.solidrust.ai/v1"
)
# Single text embedding
response = client.embeddings.create(
model="Qwen/Qwen3-Embedding-0.6B",
input="The quick brown fox jumps over the lazy dog."
)
embedding = response.data[0].embedding
print(f"Embedding dimension: {len(embedding)}")
print(f"First 5 values: {embedding[:5]}")
# Multiple texts at once
response = client.embeddings.create(
model="Qwen/Qwen3-Embedding-0.6B",
input=[
"First document text",
"Second document text",
"Third document text"
]
)
for i, item in enumerate(response.data):
print(f"Document {i}: {len(item.embedding)} dimensions")
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0123, -0.0456, 0.0789, ...]
}
],
"model": "Qwen/Qwen3-Embedding-0.6B",
"usage": {
"prompt_tokens": 10,
"total_tokens": 10
}
}

For production use, store your API key in environment variables rather than hardcoding it.

import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ.get("SOLIDRUST_API_KEY"),
base_url=os.environ.get("SOLIDRUST_BASE_URL", "https://api.solidrust.ai/v1")
)

.env file:

Terminal window
SOLIDRUST_API_KEY=your_api_key_here
SOLIDRUST_BASE_URL=https://api.solidrust.ai/v1

Handle API errors gracefully in your application.

from openai import OpenAI, APIError, RateLimitError, AuthenticationError
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.solidrust.ai/v1"
)
try:
response = client.chat.completions.create(
model="vllm-primary",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)
except AuthenticationError:
print("Invalid API key. Get one at console.solidrust.ai")
except RateLimitError:
print("Rate limit exceeded. Please retry after a short delay.")
except APIError as e:
print(f"API error: {e.status_code} - {e.message}")
except Exception as e:
print(f"Unexpected error: {e}")