AI21 Labs empowers developers and businesses with a suite of Text Processing APIs designed to unlock the potential of text data. These APIs leverage cutting-edge AI models to perform a variety of tasks, including:

  • Creative Text Generation: Generate different creative text formats like poems, scripts, or marketing copy.
  • Text Analysis and Understanding: Gain insights into text sentiment, topics, and characteristics.
  • Text Transformation: Improve readability and clarity by paraphrasing or summarizing content.

All AI21 Labs Text Processing APIs require authentication using an API key. You can obtain your API key by creating a free account on the AI21 Labs platform.

Here's a breakdown of some key AI21 Labs Text Processing APIs along with example code snippets in JavaScript:

Authentication:

  • Method: Bearer Token Authorization
  • Header: Authorization
  • Value: Bearer <Your_API_Key> (Replace <Your_API_Key> with your actual API key)

Text Processing API Endpoints:

1. Text Completion API (Complete)

  • About: This API allows you to generate different creative text formats based on a provided prompt and instructions.
  • Type: POST
  • JavaScript Example:
const apiKey = 'YOUR_API_KEY';
const url = 'https://api.genny.ai21.com/api/v1/complete';

const data = {
    text: 'Once upon a time',
    instructions: 'Continue the story in a creative and imaginative way',
};

const headers = {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
};

fetch(url, { method: 'POST', headers, body: JSON.stringify(data) })
    .then((response) => response.json())
    .then((data) => {
        console.log('Generated Text:', data.completions[0].text);
    })
    .catch((error) => console.error(error));

2. Summarization API (Summarize)

  • About: This API generates concise summaries of factual text content.
  • Type: POST
  • JavaScript Example:
const apiKey = 'YOUR_API_KEY';
const url = 'https://api.genny.ai21.com/api/v1/summarize';

const data = {
    text: 'The quick brown fox jumps over the lazy dog. The rain in Spain falls mainly on the plain.',
};

const headers = {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
};

fetch(url, { method: 'POST', headers, body: JSON.stringify(data) })
    .then((response) => response.json())
    .then((data) => {
        console.log('Summary:', data.summary);
    })
    .catch((error) => console.error(error));

3. Paraphrase API (Paraphrase)

  • About: This API rewrites sentences while preserving the original meaning.
  • Type: POST
  • JavaScript Example:
const apiKey = 'YOUR_API_KEY';
const url = 'https://api.genny.ai21.com/api/v1/paraphrase';

const data = {
    text: 'This is a clear and concise sentence.',
};

const headers = {
    Authorization: `Bearer ${apiKey}`,
    'Content-Type': 'application/json',
};

fetch(url, { method: 'POST', headers, body: JSON.stringify(data) })
    .then((response) => response.json())
    .then((data) => {
        console.log('Paraphrased Text:', data.paraphrases[0].text);
    })
    .catch((error) => console.error(error));

4. Text Analysis API (Analyze) (Available on paid plans)

  • About: This API analyzes the sentiment and other characteristics of a text.
  • Type: POST
  • Note: Text Analysis API requires a paid subscription. Refer to AI21 Labs documentation for details on paid plans and functionalities.

5. Text Embeddings API (Embeddings) (Available on paid plans)

  • About: This API transforms text into numerical representations for various NLP tasks.
  • Type: POST
  • Note: Text Embeddings API requires a paid subscription. Refer to AI21 Labs documentation for details on paid plans and functionalities.

These are just a few examples of the powerful