Integrate the API

🔌 API Integration Guide

You can interact with Eden AI’s assistant feature programmatically using simple REST API calls. This allows you to upload data and query your assistant directly from your backend or scripts.


📄 Add Text via API

Use this endpoint to upload plain text directly:

import json
import requests

headers = {"Authorization": "Bearer 🔑 Your_API_Key"}
url = "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/add_text"              	 

payload = {
    "texts": ["first text"],
    "metadata": [{"filter1": "value"}]  # Optional
}

response = requests.post(url, json=payload, headers=headers)
print(response.status_code)

 
const axios = require("axios").default;

const addText = async () => {
  try {
    const response = await axios.post(
      "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/add_text",
      {
        texts: ["first text"],
        metadata: [{ filter1: "value" }] // Optional
      },
      {
        headers: {
          Authorization: "Bearer 🔑 Your_API_Key",
        },
      }
    );

    console.log("Status:", response.status);
  } catch (error) {
    console.error(error);
  }
};

addText();

🔗 Add URL via API

Use this to upload content from a public web page:

import json
import requests

headers = {"Authorization": "Bearer 🔑 Your_API_Key"}
url = "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/add_url"              	 

payload = {
    "urls": ["https://en.wikipedia.org/wiki/Shrek"],
    "metadata": [{"filter1": "value"}]  # Optional
}

response = requests.post(url, json=payload, headers=headers)
print(response.status_code)

 
const axios = require("axios").default;

const addUrl = async () => {
  try {
    const response = await axios.post(
      "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/add_url",
      {
        urls: ["https://en.wikipedia.org/wiki/Shrek"],
        metadata: [{ filter1: "value" }] // Optional
      },
      {
        headers: {
          Authorization: "Bearer 🔑 Your_API_Key",
        },
      }
    );

    console.log("Status:", response.status);
  } catch (error) {
    console.error(error);
  }
};

addUrl();


📁 Add File via API

Upload PDF, audio, or CSV files to be used by your assistant:

import json
import requests

headers = {"Authorization": "Bearer 🔑 Your_API_Key"}
url = "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/add_file"

data = {
    "data_type": "audio",  # Options: "audio", "pdf", "csv"
    "provider": "deepgram",  # Required for audio
    "metadata": json.dumps({"metadata1": "value1"})  # Optional
}

files = {"file": open("path/to/your/audio.mp3", "rb")}

response = requests.post(url, data=data, files=files, headers=headers)
print(response.status_code)

const axios = require("axios").default;
const FormData = require("form-data");
const fs = require("fs");

const addFile = async () => {
  const form = new FormData();
  form.append("data_type", "audio"); // "audio", "pdf", or "csv"
  form.append("provider", "deepgram"); // Optional for CSV
  form.append("metadata", JSON.stringify({ metadata1: "value1" }));
  form.append("file", fs.createReadStream("path/to/your/audio.mp3"));

  try {
    const response = await axios.post(
      "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/add_file",
      form,
      {
        headers: {
          Authorization: "Bearer 🔑 Your_API_Key",
          ...form.getHeaders(),
        },
      }
    );

    console.log("Status:", response.status);
  } catch (error) {
    console.error(error);
  }
};

addFile();

💬 Ask a Question via API

Query your assistant using your uploaded content and settings.

import json
import requests

headers = {"Authorization": "Bearer 🔑 Your_API_Key"}
url = "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/ask_llm"

payload = {
    "query": "Which product is the most expensive?",
    "llm_provider": "openai",
    "llm_model": "gpt-4", 
    "k": 5,
    "filter_documents": {"metadata1": "value1"},
    "max_tokens": 100,
    "temperature": 0
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
const axios = require("axios").default;

const options = {
  method: "POST",
  url: "https://api.edenai.run/v2/aiproducts/askyoda/v2/{project_id}/ask_llm",
  headers: {
    Authorization: "Bearer 🔑 Your_API_Key",
  },
  data: {
    query: "Which product is the most expensive?",
    llm_provider: "openai",
    llm_model: "gpt-4",
    k: 5,
    filter_documents: {"metadata1": "value1"},
    max_tokens: 100,
    temperature: 0,
  },
};

axios
  .request(options)
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error(error);
  });

🔁 Replace {project_id} with your actual project ID and Your_API_Key with your Eden AI API key.
This setup gives you full control to build and scale your assistant directly from code.