Getting Started with Praxos API

This quickstart guide will help you get up and running using Praxos. You’ll learn how to:

  • Set up a development environment
  • Upload a document
  • Run a query on your document
  • Retrieve and handle the results

Prerequisites

To begin, make sure you have:

  • A Praxos API key (see API Key Instructions)
  • Python 3.6 or higher installed
  • A JSON/PDF/DOC/DOCX file to analyze

Setup Your Development Environment

First, Python dependencies:

pip install requests

Then, add your API key to the Python environment:

import requests

# Replace with your actual API key
API_KEY = "YOUR_API_KEY"

Upload Your Document

Upload a JSON/PDF/DOC/DOCX document to Praxos. The system will automatically handle OCR if needed.

# API endpoint for uploading documents
upload_source_url = "https://api.praxos.ai/add-source"

# Path to your PDF file
pdf_file_path = 'path/to/your/file.pdf'

# Set up headers with your API key
headers = {
    "API-key": API_KEY,
}

try:
    # Open and upload the file
    with open(pdf_file_path, 'rb') as f:
        files = {'file': (pdf_file_path, f, 'application/pdf')}
        response = requests.post(upload_source_url, headers=headers, files=files)
        
        # Check if the request was successful
        if response.status_code == 200:
            result = response.json()
            source_id = result['source_id']
            print(f"Successfully uploaded document, Source ID: {source_id}.\n response: {result}")
        else:
            print(f"Error uploading document: {response.text}")
except Exception as e:
    print(f"An error occurred: {str(e)}")

Expected successful response:

Successfully uploaded document, Source ID: SOURCE_ID 
response:
{
    "source_id": "SOURCE_ID"
}

Run a Query

Now that your document is uploaded, you can run queries against it. You’ll need your interface ID for this step (see Interface ID Instructions).

# API endpoint for running queries
query_url = "https://api.praxos.ai/query"

# Replace with your actual interface ID
interface_id = "INTERFACE_ID"

headers = {
    "API-key": API_KEY,
}

# Prepare the query payload
payload = {
    "queries": [
        {
            "source_ids": [source_id],
            "interface_id": interface_id
        }
    ]
}

try:
    response = requests.post(query_url, headers=headers, json=payload)
    
    if response.status_code == 200:
        result = response.json()
        job_id = result['queries'][0]['job_id']
        print(f"Query submitted successfully. Job ID: {job_id}\nresponse: {result}")
    else:
        print(f"Error submitting query: {response.text}")
except Exception as e:
    print(f"An error occurred: {str(e)}")

Expected successful response:

Query submitted successfully. Job ID: JOB_ID
response: {
    "message": "Successfully accepted 1 jobs for processing.",
    "queries": [{
        "source_ids": ["SOURCE_ID"],
        "interface_id": "INTERFACE_ID",
        "job_id": "JOB_ID"
    }]
}

Retrieve Query Results

After submitting a query, you’ll need to check the job status and retrieve the results. The processing time may vary depending on the document size and complexity.

# API endpoint for retrieving results
get_result_url = "https://api.praxos.ai/get-result"

headers = {
    "API-key": API_KEY,
}

payload = {
    "job_ids": [job_id]
}

try:
    response = requests.post(get_result_url, headers=headers, json=payload)
    
    if response.status_code == 200:
        result = response.json()
        job_response = result['results'][job_id]
        
        if job_response['status'] == 'success':
            print("Query results:")
            print(job_response['results'])
        else:
            print(f"Job status: {job_response['status']}")
            print("Please wait and try again later.")
    else:
        print(f"Error retrieving results: {response.text}")
except Exception as e:
    print(f"An error occurred: {str(e)}")

Congratulations! You’ve successfully:

  1. Set up your development environment
  2. Uploaded a document to Praxos
  3. Run a query against your document
  4. Retrieved the results