SDKs overview
DeepAI offers Software Development Kits (SDKs) and client libraries designed to facilitate interaction with its machine learning model APIs. These tools encapsulate the underlying HTTP requests and responses, allowing developers to integrate generative AI capabilities into their applications using familiar programming language constructs. The primary focus of official support is on Python and Node.js, reflecting common development environments for AI-driven applications. Beyond official offerings, a range of community-contributed libraries extends support to other languages and frameworks, providing flexibility for diverse projects. The DeepAI API documentation provides comprehensive details on available endpoints and parameters for direct HTTP interactions, which the SDKs abstract for ease of use DeepAI Machine Learning Model API reference.
Integrating DeepAI's generative models, such as image and text generation, often involves sending input parameters (e.g., text prompts for image generation, or context for text completion) and processing the returned output. SDKs streamline this process by providing functions that map directly to API endpoints, handle authentication, and parse responses into native data structures. This approach aims to reduce the boilerplate code required for API integration, allowing developers to focus on application logic rather than HTTP communication protocols Mozilla Developer Network SDK definition.
Official SDKs by language
DeepAI maintains official SDKs for Python and Node.js. These libraries are developed and supported by DeepAI to ensure compatibility and optimal performance with their API endpoints. They include features such as API key management, error handling, and structured access to various machine learning models, including image generation, text generation, and image editing. The official documentation serves as the authoritative source for installation, configuration, and usage of these SDKs.
| Language | Package Name | Installation Command | Maturity |
|---|---|---|---|
| Python | deepai |
pip install deepai |
Stable |
| Node.js | deepai |
npm install deepai |
Stable |
Installation
To begin using DeepAI's services, developers first need to obtain an API key, available after registering on the DeepAI website. This key authenticates requests made through the SDKs. Installation of the SDKs is typically performed using standard package managers for each respective language environment.
Python SDK Installation
The Python SDK can be installed using pip, the Python package installer. It requires a compatible Python version, generally Python 3.6 or newer. After installation, the library can be imported into Python scripts or interactive sessions.
pip install deepai
For virtual environments, developers might first create and activate a virtual environment to manage dependencies:
python3 -m venv deepai_env
source deepai_env/bin/activate # On Windows: deepai_env\Scripts\activate
pip install deepai
Node.js SDK Installation
The Node.js SDK is available via npm, the Node.js package manager. It is compatible with recent Node.js LTS versions. Installation typically involves adding the package to a Node.js project:
npm install deepai
To include it as a project dependency and save it to package.json:
npm install deepai --save
Quickstart example
The following examples demonstrate how to use the official DeepAI SDKs to perform a common generative AI task: generating an image from a text prompt. These examples assume that the respective SDK has been installed and that a DeepAI API key is available.
Python Quickstart: Generating an Image
This Python example uses the deepai library to generate an image based on a text input. The API key should be set either as an environment variable or directly in the script for demonstration purposes (though environment variables are recommended for production). The example provides the prompt for an image and then saves the resulting image to a specified file.
import deepai
# Replace 'YOUR_API_KEY' with your actual DeepAI API key
deepai.set_api_key('YOUR_API_KEY')
try:
response = deepai.call_api("text2img", {
"text": "a photo of a futuristic city at sunset, highly detailed, cyberpunk style",
})
image_url = response['output_url']
print(f"Generated image URL: {image_url}")
# Optional: Download the image
import requests
img_data = requests.get(image_url).content
with open('futuristic_city.jpg', 'wb') as handler:
handler.write(img_data)
print("Image saved as futuristic_city.jpg")
except deepai.DeepAIError as e:
print(f"DeepAI API Error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Node.js Quickstart: Generating an Image
This Node.js example performs the same image generation task using the deepai package. It demonstrates how to initialize the library with an API key and then call the text2img model. The resulting image URL is logged to the console. Error handling is included to catch potential issues during the API call.
const deepai = require('deepai');
// Replace 'YOUR_API_KEY' with your actual DeepAI API key
deepai.setApiKey('YOUR_API_KEY');
(async function() {
try {
const response = await deepai.callStandardApi("text2img", {
text: "a photo of a futuristic city at sunset, highly detailed, cyberpunk style",
});
const imageUrl = response.output_url;
console.log(`Generated image URL: ${imageUrl}`);
// Optional: Download the image (requires an additional library like 'node-fetch')
// const fetch = require('node-fetch');
// const fs = require('fs');
// const imageResponse = await fetch(imageUrl);
// const buffer = await imageResponse.buffer();
// fs.writeFileSync('futuristic_city.jpg', buffer);
// console.log("Image saved as futuristic_city.jpg");
} catch (error) {
console.error("DeepAI API Error:", error);
}
})();
Community libraries
While DeepAI provides official SDKs for Python and Node.js, the developer community has extended support to other programming languages and frameworks through third-party libraries. These community-contributed tools are not officially maintained by DeepAI, but they can offer alternatives for developers working in environments not directly covered by official SDKs. For example, developers might find wrappers for languages like PHP, Ruby, or Go, or integrations with specific web frameworks. The availability and maturity of these community libraries can vary significantly DeepAI community libraries search.
Developers considering community libraries should review their documentation, community support, and recent update history to ensure they are well-maintained and compatible with the latest DeepAI API versions. These libraries often follow the patterns established by the official SDKs, abstracting API calls and handling data serialization and deserialization. However, due to their unofficial nature, developers might need to contribute to their maintenance or adapt them for specific use cases.
For direct API interaction without an SDK, DeepAI also supports standard HTTP requests using tools like cURL, which can be integrated into any programming language capable of making web requests DeepAI cURL examples. This provides a universal fallback for environments where no suitable SDK, official or community, is available.