Getting started overview

Integrating DeepAI's machine learning models involves a sequential process: account creation, API key retrieval, and making authenticated requests to specific model endpoints. DeepAI offers APIs for various generative AI tasks, including image generation, text generation, and image editing. The platform supports a pay-as-you-go model, with a free tier allowing initial experimentation. Communication with the API is typically done over HTTP using a unique API key for authentication.

The following table provides a quick reference for the steps required to get started with DeepAI:

Step What to do Where
1. Sign Up Create a user account. DeepAI Homepage
2. Get API Key Retrieve your unique API key from your account dashboard. DeepAI Account Dashboard
3. Install Client (Optional) Install a recommended client library (e.g., Python requests, Node.js axios) for simplified API interaction. Package managers (pip, npm)
4. Make Request Send an authenticated HTTP POST request to a model endpoint. DeepAI API Documentation
5. Process Response Handle the JSON response from the API. Your application code

Create an account and get keys

To begin using DeepAI, you must first create an account and obtain your unique API key. The API key serves as your authentication credential for all requests made to the DeepAI API.

  1. Navigate to the DeepAI homepage: Open your web browser and go to deepai.org.
  2. Sign Up: Locate the 'Sign Up' or 'Get Started' button, typically in the top right corner, and click it.
  3. Complete Registration: Provide the required information (e.g., email address, password) to create your account. Follow any email verification steps if prompted.
  4. Access Dashboard: Once registered and logged in, you will be redirected to your DeepAI account dashboard.
  5. Retrieve API Key: Your API key is usually displayed prominently within your dashboard or accessible via a dedicated 'API Keys' or 'Settings' section. Copy this key, as it will be used in your API requests. Treat your API key as sensitive information; it should not be exposed in client-side code or publicly accessible repositories.

Your first request

After obtaining your API key, you can make your first API call. This example demonstrates generating an image using the DeepAI Text-to-Image API. This model takes text input and generates an image based on the prompt.

Prerequisites

  • Your DeepAI API key.
  • A command-line interface (for cURL) or a programming environment with an HTTP client library (for Python/Node.js).

Example: Text-to-Image Generation

The DeepAI Text-to-Image model allows you to convert a text description into an image. The API endpoint for this model is https://api.deepai.org/api/text2img.

cURL Example

Using cURL is a direct way to test the API from your terminal:

curl \
  -H "api-key: YOUR_DEEPAI_API_KEY" \
  -F "text=a futuristic city at sunset" \
  https://api.deepai.org/api/text2img

Replace YOUR_DEEPAI_API_KEY with your actual API key. The -F "text=..." parameter provides the textual prompt for image generation. For more details on cURL and HTTP requests, consult the cURL official documentation.

Python Example

For Python, you can use the requests library. First, install it if you haven't already:

pip install requests

Then, execute the following Python code:

import requests

r = requests.post(
    "https://api.deepai.org/api/text2img",
    data={
        'text': 'a medieval knight in shining armor',
    },
    headers={'api-key': 'YOUR_DEEPAI_API_KEY'}
)
print(r.json())

This script sends a POST request with the text prompt and your API key in the headers. The response will be parsed as JSON, containing the URL of the generated image and other metadata.

Node.js Example

For Node.js, the axios library is a common choice for making HTTP requests. Install it first:

npm install axios

Then, use the following JavaScript code:

const axios = require('axios');

async function generateImage() {
  try {
    const response = await axios.post(
      'https://api.deepai.org/api/text2img',
      {
        text: 'a cyberpunk alleyway with neon signs',
      },
      {
        headers: { 'api-key': 'YOUR_DEEPAI_API_KEY' },
      }
    );
    console.log(response.data);
  } catch (error) {
    console.error('Error generating image:', error.response ? error.response.data : error.message);
  }
}

generateImage();

This Node.js example performs a similar POST request. Ensure you replace YOUR_DEEPAI_API_KEY with your key. The async function handles the API call and logs the JSON response. For robust error handling in Axios, refer to the Axios error handling guide.

Common next steps

After successfully making your first API call, consider these common next steps to further integrate and optimize your use of DeepAI:

  • Explore other models: DeepAI offers a range of different AI models, including image editing, super-resolution, and various text generation tasks. Review the API documentation to find models relevant to your project.
  • Integrate into your application: Move beyond simple test scripts and integrate the API calls into your primary application logic. This usually involves building functions or services that abstract the API interaction.
  • Handle responses and errors: Implement robust error handling and parse the API responses effectively. For image generation, this typically means extracting image URLs and displaying them. For other models, it might involve processing generated text or data.
  • Manage API usage and billing: Monitor your API call usage through your DeepAI dashboard. Review the DeepAI pricing page to understand the cost implications beyond the free tier and set up billing if necessary.
  • Implement rate limiting: If your application makes frequent requests, implement client-side rate limiting to avoid exceeding DeepAI's API rate limits and ensure fair usage.
  • Secure your API key: Ensure your API key is stored securely (e.g., environment variables, secret management services) and not hardcoded into your application or committed to version control.

Troubleshooting the first call

Encountering issues during your first API call is common. Here are troubleshooting steps for frequent problems:

  • Invalid API Key:
    • Symptom: HTTP 401 Unauthorized error or similar access denied message.
    • Solution: Double-check that you have copied your API key correctly from your DeepAI dashboard. Ensure there are no leading or trailing spaces. Verify it's passed in the api-key header, not as a query parameter or in the request body, unless specifically stated by the model documentation.
  • Incorrect Endpoint or Method:
    • Symptom: HTTP 404 Not Found or HTTP 405 Method Not Allowed error.
    • Solution: Confirm the entire URL for the API endpoint is correct for the model you are using. Verify that you are using the correct HTTP method (e.g., POST for most DeepAI generative models) as specified in the DeepAI API documentation.
  • Missing or Malformed Parameters:
    • Symptom: HTTP 400 Bad Request error.
    • Solution: Ensure all required parameters (e.g., text for text-to-image) are present and correctly formatted in the request body. Check the data type and format expected for each parameter. For form data, ensure your HTTP client is sending it as multipart/form-data or application/x-www-form-urlencoded as appropriate.
  • Rate Limit Exceeded:
    • Symptom: HTTP 429 Too Many Requests error.
    • Solution: If you are on the free tier, you have 5 calls per day. Wait until the next day or purchase additional credits via the DeepAI pricing page. Implement backoff and retry logic in your application for production use.
  • Network Issues:
    • Symptom: Connection timeouts or network unreachable errors.
    • Solution: Verify your internet connection. Check for any firewall or proxy settings that might be blocking outbound HTTP requests from your environment.