Getting Started
Welcome to the Infuzu API! This guide will help you quickly set up and start using the Infuzu API to leverage the power of Intelligent Model Selection (IMS) for your applications. Whether you're a seasoned developer or just getting started, this guide provides all the essential steps to integrate the Infuzu API into your workflow.
Prerequisites
Before you begin, ensure you have the following:
Python 3.8 or higher installed on your machine. You can download it from the official Python website.
cURL installed for making HTTP requests from the command line. Most Unix-based systems come with cURL pre-installed. For Windows, you can download it from the cURL official website.
An Infuzu API Key. If you don't have one yet, follow the instructions in the Obtaining Your API Key section.
Obtaining Your API Key
To interact with the Infuzu API, you'll need a valid API key. Follow these steps to obtain your API key:
Access the Infuzu Dashboard:
Navigate to the API Key Management page.
Generate a New API Key:
Click on the "Create New API Key" button.
Provide a name or description for the key to help you identify its usage.
Click "Generate" to create the key.
Copy Your API Key:
Once generated, copy the API key and store it securely.
Installing the Python Library
Infuzu provides a Python library to simplify interactions with the API. Follow these steps to install and set up the library:
Install via pip:
Open your terminal or command prompt and run:
pip install infuzuVerify Installation:
After installation, you can verify it by importing the library in Python:
import infuzu print(infuzu.get_version())This should display the installed version of the
infuzu
library.
Setting Up Environment Variables
For security and convenience, it's recommended to store your API key as an environment variable. This way, you don't have to include the key directly in your code.
Setting INFUZU_API_KEY
On Unix/Linux/macOS
Temporary (Session Only):
export INFUZU_API_KEY="your_api_key_here"This sets the variable for the current terminal session.
Permanent (Across Sessions):
Add the following line to your
~/.bashrc
,~/.bash_profile
, or~/.zshrc
file:export INFUZU_API_KEY="your_api_key_here"After adding, reload the file:
source ~/.bashrc
On Windows
Using Command Prompt (Temporary):
set INFUZU_API_KEY=your_api_key_hereUsing PowerShell (Temporary):
$env:INFUZU_API_KEY="your_api_key_here"Permanent (Across Sessions):
Open System Properties > Advanced > Environment Variables.
Click New under User variables.
Set Variable name to
INFUZU_API_KEY
and Variable value to your API key.Click OK to save.
Making Your First API Request
Once you've set up your environment, you're ready to make your first API request. We'll demonstrate how to create a chat completion using both cURL and Python.
Using cURL
Here's how you can make a basic chat completion request using cURL:
Explanation:
Endpoint:
https://chat.infuzu.com/api/v1/chat/completions
Headers:
Content-Type: application/json
: Specifies the request body format.Infuzu-API-Key
: Your unique API key for authentication.
Payload:
messages
: A list of message objects. Each message has arole
(e.g., "user" or "assistant") andcontent
.model
: Specifies which model to use."infuzu-ims"
uses Infuzu's Intelligent Model Selection.
Using Python
Below is a Python example using the Infuzu Python library to create a chat completion:
Explanation:
Import Required Modules:
os
for accessing environment variables.create_chat_completion
and related classes from theinfuzu
library.
Retrieve API Key:
The API key is fetched from the
INFUZU_API_KEY
environment variable.
Define Messages:
Create a list of
ChatCompletionsHandlerRequestMessage
objects representing the conversation history.
Make the API Request:
Call
create_chat_completion
with the messages, API key, and model.
Handle the Response:
Upon success, print the response ID and message content.
Handle potential errors using
InfuzuAPIError
.
Understanding the Basic Workflow
Here's a high-level overview of how to interact with the Infuzu API:
Setup:
Install the Python library.
Obtain and securely store your API key.
Set up environment variables for easy access.
Constructing the Request:
Define your conversation messages with appropriate roles and content.
Optionally, customize model selection parameters like preferred models, cost limits, and weighting factors.
Making the Request:
Use either cURL or the Python library to send a POST request to the
/v1/chat/completions
endpoint.Include necessary headers and the JSON payload.
Processing the Response:
Receive a
ChatCompletionsObject
containing the AI's response(s), metadata, and usage information.Handle any errors or warnings as needed.
Managing Usage and Billing:
Monitor your API usage and credits via the provided dashboard links.
Implement error handling to manage rate limits and billing constraints.
Managing API Credits and Usage
Efficiently managing your API credits and understanding your usage patterns is crucial for optimizing costs and ensuring seamless integration. Here are key resources and steps to help you manage your API usage effectively:
Dashboard Links
Managing API Credits:
Manage your API credits, view billing history, and update payment methods.
Viewing Rate Limits:
Check your organization's rate limits to ensure you stay within allowed usage.
Monitoring Usage Patterns:
Analyze your API usage trends, peak usage times, and breakdown by endpoints.
Managing API Keys:
Create, revoke, and manage your API keys securely.
Setting Organization API Pricing:
Customize pricing plans for your organization based on usage and requirements.
Best Practices
Monitor Regularly:
Regularly check your usage dashboards to stay informed about your consumption and costs.
Set Alerts:
Configure alerts for when you approach your rate limits or budget thresholds to prevent unexpected overages.
Optimize Requests:
Structure your requests efficiently to minimize unnecessary usage. For example, avoid excessive message history if not needed.
Manage API Keys:
Rotate API keys periodically and revoke any that are no longer in use to maintain security.
For comprehensive on each topic, navigate through the rest of our documentation. Happy coding!