Copilot Creation - API Guide

These APIs empower developers to create AI copilots tailored to their unique knowledge bases. With this versatile toolkit, you can design custom copilots, enrich them with domain-specific knowledge, and interact with them to gain expert insights - perfect for building intelligent assistants for specialized industries or enterprise workflows.

Base URL for all endpoints: https://api.insituate.ai

Authentication Endpoints

Step 1. GetAuth

Authenticates a user and returns a JWT token.

  • URL: /auth/login
  • Method: POST
  • Content-Type: application/json
Request Body:
{
    "email": "username",
    "password": "password"
}
1 def get_auth_token(email, password):
2    endpoint = "https://api.insituate.ai/auth/login"
3    payload = {
4        "email": email,
5        "password": password
6    }
7    response = requests.post(endpoint, json=payload)
8    return response.json()["token"]
1 curl -X POST \\
2  'https://api.insituate.ai/auth/login' \\
3  -H 'Content-Type: application/json' \\
4  -d '{
5    "email": "username",
6    "password": "password"
7}'
Success Response:
{
    "message": "Login successful",
    "token": "jwt_token_string",
    "user_id": "user_id_string",
    "email": "username"
}

Copilot Endpoints

Step 1. Create Copilot

Creates a new copilot instance with a specified name.

  • URL: /copilots/create
  • Method: POST
  • Auth Required: Yes
Request Body:
{
    "name": "string"
}
1 def create_copilot(token, name):
2    headers = {"Authorization": f"Bearer {token}"}
3    endpoint = "https://api.insituate.ai/copilots/create"
4    payload = {"name": name}
5    response = requests.post(endpoint, json=payload, headers=headers)
6    return response.json()
1 curl -X POST \\
2  'https://api.insituate.ai/copilots/create' \\
3  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \\
4  -H 'Content-Type: application/json' \\
5  -d '{"name": "Tax Assistant"}'

Step 2. Add Knowledge

Adds documents to a copilot's knowledge base.

  • URL: /copilots/add_knowledge
  • Method: POST
  • Auth Required: Yes
  • Content-Type: multipart/form-data
1 def add_knowledge(token, copilot_id, file_paths):
2    headers = {"Authorization": f"Bearer {token}"}
3    endpoint = "https://api.insituate.ai/copilots/add_knowledge"
4
5    files = []
6    for file_path in file_paths:
7        files.append(('files', open(file_path, 'rb')))
8
9    data = {'copilot_id': copilot_id}
10    response = requests.post(endpoint, data=data, files=files, headers=headers)
11
12    # Close files
13    for _, file_obj in files:
14        file_obj.close()
15
16    return response.json()
1 curl -X POST \\
2  'https://api.insituate.ai/copilots/add_knowledge' \\
3  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \\
4  -F 'copilot_id=your_copilot_id' \\
5  -F 'files=@/path/to/document.pdf'

Step 3. Query Copilot

Queries the copilot using uploaded knowledge.

  • URL: /copilots/query
  • Method: POST
  • Auth Required: Yes
1 def query_copilot(token, copilot_id, prompt):
2    headers = {"Authorization": f"Bearer {token}"}
3    endpoint = "https://api.insituate.ai/copilots/query"
4    payload = {
5        "copilot_id": copilot_id,
6        "prompt": prompt
7    }
8    response = requests.post(endpoint, json=payload, headers=headers)
9    return response.json()
1 curl -X POST \\
2  'https://api.insituate.ai/copilots/add_knowledge' \\
3  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \\
4  -F 'copilot_id=your_copilot_id' \\
5  -F 'files=@/path/to/document.pdf'

Complete Implementation Example

Here's a complete example showing how to use all the APIs together:

1 import requests
2 import os
3
4 class InsituateClient:
5    def __init__(self, base_url="https://api.insituate.ai"):
6        self.base_url = base_url
7        self.token = None
8        self.headers = None
9        self.copilot_id = None
10
11    def login(self, email="username", password="password"):
12        """Login and get JWT token"""
13        endpoint = f"{self.base_url}/auth/login"
14        payload = {
15            "email": email,
16            "password": password
17        }
18        response = requests.post(endpoint, json=payload)
19        if response.status_code == 200:
20            self.token = response.json()["token"]
21            self.headers = {"Authorization": f"Bearer {self.token}"}
22            return True
23        return False
24
25    def create_copilot(self, name):
26        """Create a new copilot"""
27        if not self.token:
28            raise ValueError("Not authenticated. Call login() first.")
29
30        endpoint = f"{self.base_url}/copilots/create"
31        payload = {"name": name}
32        response = requests.post(endpoint, json=payload, headers=self.headers)
33        if response.status_code == 201:
34            self.copilot_id = response.json()["copilot_id"]
35            return response.json()
36        return None
37
38    def add_knowledge(self, file_paths):
39        """Add documents to copilot"""
40        if not self.copilot_id:
41            raise ValueError("No copilot created. Call create_copilot() first.")
42
43        endpoint = f"{self.base_url}/copilots/add_knowledge"
44        files = [('files', open(path, 'rb')) for path in file_paths]
45        data = {'copilot_id': self.copilot_id}
46
47        response = requests.post(endpoint, data=data, files=files, headers=self.headers)
48
49        # Close files
50        for _, file_obj in files:
51            file_obj.close()
52
53        return response.json()
54
55    def query(self, prompt):
56        """Query the copilot"""
57        if not self.copilot_id:
58            raise ValueError("No copilot created. Call create_copilot() first.")
59
60        endpoint = f"{self.base_url}/copilots/query"
61        payload = {
62            "copilot_id": self.copilot_id,
63            "prompt": prompt
64        }
65        response = requests.post(endpoint, json=payload, headers=self.headers)
66        return response.json()
67
68 # Usage Example
69 def main():
70    # Initialize client
71    client = InsituateClient()
72
73    # Login
74    if not client.login("username", "password"):
75        print("Login failed")
76        return
77
78    # Create copilot
79    copilot = client.create_copilot("Tax Assistant")
80    if not copilot:
81        print("Failed to create copilot")
82        return
83
84    # Add documents
85    documents = ["tax_guidelines.pdf", "regulations.txt"]
86    result = client.add_knowledge(documents)
87    print(f"Documents added: {result}")
88
89    # Query the copilot
90    response = client.query("What are the tax implications for underpayment?")
91    print(f"Answer: {response['answer']}")
92
93 if __name__ == "__main__":
94    main()
1curl -X POST \\
2  'https://api.insituate.ai/copilots/add_knowledge' \\
3  -H 'Authorization: Bearer YOUR_JWT_TOKEN' \\
4  -F 'copilot_id=your_copilot_id' \\
5  -F 'files=@/path/to/document.pdf'

Notes

  1. Supported file types: PDF, TXT
  2. All endpoints except login require JWT authentication
  3. JWT tokens expire after 24 hours
  4. Files are processed and stored securely in the copilot's knowledge base
  5. Always close file handles after uploading documents
  6. All communications are secured using HTTPS