Using AI21 with Flowstack

AI21 can be seamlessly integrated with Flowstack using REST API, Python, or Node.js. Below are the implementation details for each method.

1. Using REST API

To make a request to AI21 using the REST API, use the following Curl command. Ensure you replace YOUR_AI21_API_KEY with your actual AI21 API key.

curl -X POST "https://ai21.flowstack.ai/studio/v1/j2-light/complete" \
-H "Authorization: Bearer YOUR_AI21_API_KEY" \
-H "Content-Type: application/json" \
-H "Flowstack-Auth: Bearer YOUR_FLOWSTACK_KEY" \
-d '{"prompt": "Hello!"}'

2. Using Python

For integrating AI21 with Python, use the script below. Replace YOUR_AI21_API_KEY and YOUR_FLOWSTACK_KEY with your AI21 API key and Flowstack key, respectively.

import requests
import json

url = "https://ai21.flowstack.ai/studio/v1/j2-light/complete"

headers = {
    "Authorization": "Bearer YOUR_AI21_API_KEY",
    "Content-Type": "application/json",
    "Flowstack-Auth": "Bearer YOUR_FLOWSTACK_KEY"
}
payload = {
    "prompt": "Hello!"
}

response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)

3. Using Node.js

For Node.js integration with AI21, follow the example below. Don’t forget to replace YOUR_AI21_API_KEY and YOUR_FLOWSTACK_KEY with your respective credentials.

const axios = require('axios');

const url = "https://ai21.flowstack.ai/studio/v1/j2-light/complete";

const headers = {
    Authorization: "Bearer YOUR_AI21_API_KEY",
    "Content-Type": "application/json",
    "Flowstack-Auth": "Bearer YOUR_FLOWSTACK_KEY"
};

const payload = {
    prompt: "Hello!"
};

axios.post(url, payload, { headers: headers })
    .then(response => {
        console.log(response.data);
    })
    .catch(error => {
        console.error('Error:', error);
    });