Skip to content

aisearchapi/aisearchapi-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Search API Python Client

PyPI version Python Support License: MIT

A Python client library for the AI Search API that provides semantic search, contextual awareness, and intelligent AI-powered results.
This package makes it easy for developers to integrate the AI Search API into Python projects.

πŸ‘‰ To start, get your free API key from the AI Search API dashboard.


Features

  • πŸ” AI-Powered Semantic Search: Leverage advanced embeddings for natural language search
  • 🎯 Context Awareness: Add conversation history for smarter results
  • ⚑ Simple API Client: Clean and Pythonic interface with strong error handling
  • πŸ›‘οΈ Type Safety: Full type hints for modern development
  • πŸ”„ Flexible Output: Choose between plain text or markdown responses
  • πŸ’° Usage Tracking: Monitor your API credit balance anytime

Installation

Install from PyPI:

pip install aisearchapi-client

Or install from source:

git clone https://github.com/aisearchapi/aisearchapi-python.git
cd aisearchapi-python
pip install -e .

Quick Start

Get Your API Key

  1. Sign up at aisearchapi.io.
  2. Log in to the dashboard.
  3. Copy your API key.

Use this key when creating a client:

from aisearchapi_client import AISearchAPIClient

client = AISearchAPIClient(api_key="your-api-key-here")

Basic Usage Example

from aisearchapi_client import AISearchAPIClient

client = AISearchAPIClient(api_key="your-api-key-here")

result = client.search(
    prompt="What is machine learning and how does it work?",
    response_type="markdown"
)

print("Answer:", result.answer)
print("Sources:", result.sources)
print(f"Total time: {result.total_time}ms")

balance = client.balance()
print(f"Available credits: {balance.available_credits}")
client.close()

Advanced Usage

Contextual Search

from aisearchapi_client import AISearchAPIClient, ChatMessage

with AISearchAPIClient(api_key="your-api-key-here") as client:
    result = client.search(
        prompt="What are the main advantages and disadvantages?",
        context=[
            ChatMessage(role="user", content="I am researching solar energy for my home"),
            ChatMessage(role="user", content="I live in a sunny climate with high electricity costs")
        ],
        response_type="text"
    )
    print("Contextual Answer:", result.answer)

Custom Configuration

client = AISearchAPIClient(
    api_key="your-api-key-here",
    base_url="https://api.aisearchapi.io",
    timeout=60
)

API Reference

Full API reference is available in the official documentation.

AISearchAPIClient

Constructor

AISearchAPIClient(
    api_key: str,
    base_url: str = "https://api.aisearchapi.io",
    timeout: int = 30
)
  • api_key: Get yours from the dashboard
  • base_url: Optional custom endpoint
  • timeout: Timeout in seconds

Methods

  • search(prompt, context=None, response_type=None) β†’ Perform an AI-powered semantic search
  • balance() β†’ Check current credit usage

For more, see API docs.


Error Handling

from aisearchapi_client import AISearchAPIClient, AISearchAPIError

try:
    with AISearchAPIClient(api_key="your-api-key") as client:
        result = client.search(prompt="Your query")
        print(result.answer)
except AISearchAPIError as e:
    print(f"API Error [{e.status_code}]: {e.description}")

Environment Variables

You can set your API key globally:

export AI_SEARCH_API_KEY="your-api-key-here"

Then use:

import os
from aisearchapi_client import AISearchAPIClient

api_key = os.getenv("AI_SEARCH_API_KEY")
client = AISearchAPIClient(api_key=api_key)

Examples

Find more examples in the examples/ folder or check the documentation:

  • Basic search and balance checking
  • Contextual search with history
  • Async usage
  • Error handling

Requirements

  • Python 3.8+
  • requests >= 2.25.0
  • typing-extensions >= 4.0.0 (if Python < 3.10)

Development

git clone https://github.com/aisearchapi/aisearchapi-python.git
cd aisearchapi-python
python -m venv venv
source venv/bin/activate
pip install -e ".[dev,test]"
pytest

License

This project is licensed under the MIT License - see the LICENSE file.


Support & Links


SEO Keywords

AI search API Python client, semantic search Python, contextual AI search, AI API key, AI dashboard, intelligent search SDK

About

Official Python SDK for the AI Search API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •