Python SDK

Ask Sage Python Client

A powerful, easy-to-use Python library for seamless Ask Sage API integration

Table of Contents
  1. Overview
  2. Available Methods
  3. Example Notebook
  4. Quick Start Guide
  5. Additional Resources

Overview


Available Methods

Client Method Reference

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

Interactive Tutorial

Explore a comprehensive Jupyter notebook with examples and best practices for the Python client:


Quick Start Guide

Installation

Install the Ask Sage Python Client using pip:

pip install asksageclient
Documentation: Full package reference is available on PyPI.

Step 1 — Create Credentials File

Create a JSON file with your API credentials:

{
"credentials": {
"api_key": "YOUR_API_KEY",
"Ask_sage_user_info": {
  "username": "your.email@example.com"
}
}
}
Security: Never commit credentials to version control. Add credentials.json to your .gitignore file.

Step 2 — Initialize the Client

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!")

Additional Resources

Where to Go Next

Pro Tip: Join the community to stay updated on new features, best practices, and to get help from other developers.

Back to top

Copyright © 2026 Ask Sage Inc. All Rights Reserved. Ask Sage is a BigBear.ai company.