Ask Sage Python Client
A powerful, easy-to-use Python library for seamless Ask Sage API integration
Table of Contents
Instance-Specific Base URL: The endpoints and configuration shown reflect the instance at chat.asksage.ai. The api. prefix and path suffix stay the same across deployments — only the instance segment in the middle changes based on which Ask Sage instance you are logging into. Always use the instance approved by your organization and applicable regulatory requirements, and match the base URL in your configuration to the instance you authenticate against.
Overview
Available Methods
The client exposes methods covering models, queries, training, datasets, plugins/agents, and usage tracking:
| Method | Description |
|---|---|
get_models() | Retrieve all available AI models |
query() | Send queries to AI models with full customization |
query_with_file() | Query with file attachments for context |
train() | Add content to your knowledge base |
train_with_file() | Train using file uploads |
file() | Upload and process files |
add_dataset() | Create new datasets |
delete_dataset() | Remove datasets |
assign_dataset() | Assign datasets to users |
get_datasets() | List all available datasets |
get_personas() | Retrieve available AI personas |
get_plugins() | List available plugins/agents |
query_plugin() | Execute queries using specific plugins |
execute_plugin() | Run plugins with custom content |
follow_up_questions() | Generate contextual follow-up questions |
tokenizer() | Calculate token counts for content |
get_user_logs() | Retrieve user activity logs |
get_user_logins() | Get user login history |
count_monthly_tokens() | Track monthly token usage |
count_monthly_teach_tokens() | Monitor training token consumption |
Example Notebook
Quick Start Guide
Install the Ask Sage Python Client using pip:
pip install asksageclient
Default Base URL — Update for Your Tenant: Out of the box, asksageclient points at the api.asksage.ai instance. If your organization uses a different Ask Sage tenant, you must override the base URLs when initializing the client so requests are routed to the instance you authenticate against. Always use the instance approved by your organization and applicable regulatory requirements.
Pass the matching URLs via the user_base_url and server_base_url arguments shown in Step 2 below (for example, user_base_url='https://api.<your-instance>.ai/user' and server_base_url='https://api.<your-instance>.ai/server'). The api. prefix and /user/ / /server/ suffix stay the same — only the instance segment changes.
Load credentials and create an Ask Sage client instance:
import json
from asksageclient import AskSageClient
# Load credentials from file
def load_credentials(filename):
"""Load API credentials from JSON file."""
try:
with open(filename) as file:
return json.load(file)
except FileNotFoundError:
raise FileNotFoundError(f"Credentials file '{filename}' not found.")
except json.JSONDecodeError:
raise ValueError("Invalid JSON in credentials file.")
# Initialize credentials
credentials = load_credentials('credentials.json')
api_key = credentials['credentials']['api_key']
email = credentials['credentials']['Ask_sage_user_info']['username']
# Create Ask Sage client
client = AskSageClient(
email=email,
api_key=api_key,
user_base_url='https://api.asksage.ai/user', # Optional: User API base URL
server_base_url='https://api.asksage.ai/server' # Optional: Server API base URL
)
print("Ask Sage client initialized successfully!")