Integration Examples
The Integration Examples section is designed to provide practical guidance for using the Eden AI API in various programming environments.
Sample Code Snippets in Various Programming Languages
To accommodate developers working in different languages, Eden AI offers sample code snippets for popular programming languages.
Workflow with text inputs
import json
import requests
headers = {"Authorization": "Bearer your_API_key"}
url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/"
payload = {"subject":"<string value>","primary_keyword":"<string value>","secondary_keywords":"<string value>"}
response = requests.post(url, json=payload, headers=headers)
result = json.loads(response.text)
import fetch from "node-fetch"; // Only needed for Node.js, not needed in the browser
const url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/"
const payload = {"subject":"<string value>","primary_keyword":"<string value>","secondary_keywords":"<string value>"}
const launchExecution = async () => {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer your_API_key"
},
body: JSON.stringify(payload)
});
const result = await response.json()
return result;
}
const data = await launchExecution();
Workflow with file input
import json
import requests
headers = {"Authorization": "Bearer your_API_key"}
url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/"
files = {"doc_1":open('/path/to/your/doc.pdf', 'rb')}
response = requests.post(url, files=files, headers=headers)
result = json.loads(response.text)
import fs from 'fs'; // Only needed for Node.js to read the file
import fetch from "node-fetch"; // Only needed for Node.js, not needed in the browser. npm install node-fetch if not installed
import FormData from 'form-data'; // npm install --save form-data is not installed
const url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/"
const formData = new FormData();
// Append your files
formData.append('file', fs.createReadStream('/path/to/your/doc.pdf'), 'file.ext');
const launchExecution = async () => {
const response = await fetch(url, {
method: "POST",
headers: {
...formData.getHeaders(), // Add FormData headers
"Authorization": "Bearer your_API_key"
},
body: formData
});
const result = await response.json()
return result;
}
const data = await launchExecution();
Workflow with both file and text inputs
import json
import requests
headers = {"Authorization": "Bearer your_API_key"}
url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/"
files = {"audio_recording":open('/path/to/your/audio_recording.mp3', 'rb')}
payload = {"medical_role":"<string value>"}
response = requests.post(url, files=files, data=payload, headers=headers)
result = json.loads(response.text)
import fs from 'fs'; // Only needed for Node.js to read the file
import fetch from "node-fetch"; // Only needed for Node.js, not needed in the browser. npm install node-fetch if not installed
import FormData from 'form-data'; // npm install --save form-data is not installed
const url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/"
const formData = new FormData();
// Append your files
formData.append('audio_recording', fs.createReadStream('/path/to/your/audio_recording.mp3'), 'audio_recording.ext');
// Append your data
formData.append('medical_role', '<string value>');
const launchExecution = async () => {
const response = await fetch(url, {
method: "POST",
headers: {
...formData.getHeaders(), // Add FormData headers
"Authorization": "Bearer your_API_key"
},
body: formData
});
const result = await response.json()
return result;
}
const data = await launchExecution();
Get execution result
import json
import requests
headers = {"Authorization": "Bearer your_API_key"}
url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/{execution_id}/"
response = requests.get(url, headers=headers)
result = json.loads(response.text)
import fetch from "node-fetch"; // Only needed for Node.js, not needed in the browser. npm install node-fetch if not installed
const url = "https://api.edenai.run/v2/workflow/{workflow_id}/execution/{execution_id}/"
const getExecution = async () => {
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer your_API_key"
},
});
const result = await response.json();
return result;
}
const data = await getExecution();
Updated about 1 month ago