Valyu provides official SDKs for Python and TypeScript to help you integrate with our API seamlessly. This guide will help you get started with installing and setting up our SDKs.

Installation

pip install valyu

Authentication

Both SDKs require an API key for authentication. You can obtain your API key from your Valyu dashboard.

Setting up your API Key

First, set your API key as an environment variable:

# In your terminal or .env file
VALYU_API_KEY="your-api-key-here"

Initializing the Client

You can then initialize the client without explicitly passing the API key:

from valyu import Valyu

# The SDK will automatically use VALYU_API_KEY from environment
valyu = Valyu()

# Alternatively, you can still pass it explicitly if needed
valyu = Valyu(api_key="your-api-key-here")

Available Features

The Valyu SDK provides access to the following features:

  1. Context Search - Search and retrieve relevant context from our knowledge base
  2. Feedback - Submit feedback on search results using transaction IDs
  3. More features coming soon…

Quick Start

Let’s see how to use the context search feature with a simple example:

from valyu import Valyu

# Initialize the client
valyu = Valyu()

# Search for context about a specific topic
response = valyu.context(
    query="What are the benefits of renewable energy?",
    search_type="all",                    # Search both proprietary and web sources
    max_num_results=5,                    # Limit to top 5 results
    similarity_threshold=0.5,             # Only return results with >50% relevance
    query_rewrite=True                    # Enable query optimization
)

# The response includes a transaction ID that can be used for feedback
tx_id = response.tx_id
print(f"Transaction ID: {tx_id}")

# Process the results
print(response)

For detailed documentation on each feature, please refer to their respective pages:

Error Handling

The SDKs provide comprehensive error handling for different types of responses:

  • HTTP 400: Bad request errors
  • HTTP 206: Partial content responses
  • Success status in response body
try:
    # Your Valyu API calls here
    response = valyu.context(query="My query")
except ValyuError as e:
    print(f"An error occurred: {e}")