Summarize API [beta]

The Summarize API of AI21 Studio provides you access to our state-of-the-art summarization engine. It was designed specifically for summary purposes and has been fine-tuned for that task. Consequently, it's easier to integrate into your systems, and since it's optimized for this objective - it's also more efficient (and therefore cheaper) than building it from scratch.

This API takes a long piece of text and returns a summary of the text. It supports input text up to 10,000 characters long. For longer texts, you can combine it with our Slice API to summarize the text slice-by-slice.

Summarize

import requests

requests.post(
    "https://api.ai21.com/studio/v1/experimental/summarize",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "text": "We are at the start of a revolution in Natural Language Processing (NLP), or the ability of machines to understand and generate natural text. It’s no coincidence that language is a unique human ability, so making significant progress in NLP calls for considerable scientific and engineering innovations. At AI21 we aim to lead this revolution. And if we succeed, we'll have turned machines into the ultimate thought partners."
    }
)
fetch("https://api.ai21.com/studio/v1/experimental/summarize", {
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "text": "We are at the start of a revolution in Natural Language Processing (NLP), or the ability of machines to understand and generate natural text. It’s no coincidence that language is a unique human ability, so making significant progress in NLP calls for considerable scientific and engineering innovations. At AI21 we aim to lead this revolution. And if we succeed, we'll have turned machines into the ultimate thought partners."
  }),
  method: "POST"
});

curl https://api.ai21.com/studio/v1/experimental/summarize \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -X POST \
    --data-raw '{
        "text": "We are at the start of a revolution in Natural Language Processing (NLP), or the ability of machines to understand and generate natural text. It’s no coincidence that language is a unique human ability, so making significant progress in NLP calls for considerable scientific and engineering innovations. At AI21 we aim to lead this revolution. And if we succeed, we\'ll have turned machines into the ultimate thought partners."
    }' 

{
    "summaries": [
        {
            "text": "AI21 aims to lead the revolution in Natural Language Processing, which will make machines the ultimate thought partners."
        }
    ]
}

Slice API

AI21 Studio’s Slice API divides a piece of text into slices. Slices focus on distinct topics and are typically a few hundred characters long, similar to a paragraph. Therefore, slices make good inputs for Summarize API, allowing you to summarize long texts slice-by-slice.

import requests

requests.post(
    "https://api.ai21.com/studio/v1/experimental/slice",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "text": "World War II or the Second World War, often abbreviated as WWII or WW2, was a global war that lasted from 1939 to 1945. It involved the vast majority of the world'\''s countries—including all of the great powers—forming two opposing military alliances: the Allies and the Axis powers. In a total war directly involving more than 100 million personnel from more than 30 countries, the major participants threw their entire economic, industrial, and scientific capabilities behind the war effort, blurring the distinction between civilian and military resources. Aircraft played a major role in the conflict, enabling the strategic bombing of population centres and the only two uses of nuclear weapons in war. World War II was by far the deadliest conflict in human history; it resulted in 70 to 85 million fatalities, a majority being civilians. Tens of millions of people died due to genocides (including the Holocaust), starvation, massacres, and disease. In the wake of the Axis defeat, Germany and Japan were occupied, and war crimes tribunals were conducted against German and Japanese leaders. The exact causes of World War II are debated, but contributing factors included the Second Italo-Ethiopian War, the Spanish Civil War, the Second Sino-Japanese War, the Soviet–Japanese border conflicts and rising European tensions since World War I. World War II is generally considered to have begun on 1 September 1939, when Nazi Germany, under Adolf Hitler, invaded Poland. The United Kingdom and France subsequently declared war on Germany on 3 September. Under the Molotov–Ribbentrop Pact of August 1939, Germany and the Soviet Union had partitioned Poland and marked out their \"spheres of influence\" across Finland, Estonia, Latvia, Lithuania and Romania."        }
)

fetch("https://api.ai21.com/studio/v1/experimental/slice", {
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "text": "World War II or the Second World War, often abbreviated as WWII or WW2, was a global war that lasted from 1939 to 1945. It involved the vast majority of the world'\''s countries—including all of the great powers—forming two opposing military alliances: the Allies and the Axis powers. In a total war directly involving more than 100 million personnel from more than 30 countries, the major participants threw their entire economic, industrial, and scientific capabilities behind the war effort, blurring the distinction between civilian and military resources. Aircraft played a major role in the conflict, enabling the strategic bombing of population centres and the only two uses of nuclear weapons in war. World War II was by far the deadliest conflict in human history; it resulted in 70 to 85 million fatalities, a majority being civilians. Tens of millions of people died due to genocides (including the Holocaust), starvation, massacres, and disease. In the wake of the Axis defeat, Germany and Japan were occupied, and war crimes tribunals were conducted against German and Japanese leaders. The exact causes of World War II are debated, but contributing factors included the Second Italo-Ethiopian War, the Spanish Civil War, the Second Sino-Japanese War, the Soviet–Japanese border conflicts and rising European tensions since World War I. World War II is generally considered to have begun on 1 September 1939, when Nazi Germany, under Adolf Hitler, invaded Poland. The United Kingdom and France subsequently declared war on Germany on 3 September. Under the Molotov–Ribbentrop Pact of August 1939, Germany and the Soviet Union had partitioned Poland and marked out their \"spheres of influence\" across Finland, Estonia, Latvia, Lithuania and Romania."      }),
  method: "POST"
});

curl https://api.ai21.com/studio/v1/experimental/slice \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer YOUR_API_KEY' \
    -X POST \
    --data-raw '{
        "text": "World War II or the Second World War, often abbreviated as WWII or WW2, was a global war that lasted from 1939 to 1945. It involved the vast majority of the world'\''s countries—including all of the great powers—forming two opposing military alliances: the Allies and the Axis powers. In a total war directly involving more than 100 million personnel from more than 30 countries, the major participants threw their entire economic, industrial, and scientific capabilities behind the war effort, blurring the distinction between civilian and military resources. Aircraft played a major role in the conflict, enabling the strategic bombing of population centres and the only two uses of nuclear weapons in war. World War II was by far the deadliest conflict in human history; it resulted in 70 to 85 million fatalities, a majority being civilians. Tens of millions of people died due to genocides (including the Holocaust), starvation, massacres, and disease. In the wake of the Axis defeat, Germany and Japan were occupied, and war crimes tribunals were conducted against German and Japanese leaders. The exact causes of World War II are debated, but contributing factors included the Second Italo-Ethiopian War, the Spanish Civil War, the Second Sino-Japanese War, the Soviet–Japanese border conflicts and rising European tensions since World War I. World War II is generally considered to have begun on 1 September 1939, when Nazi Germany, under Adolf Hitler, invaded Poland. The United Kingdom and France subsequently declared war on Germany on 3 September. Under the Molotov–Ribbentrop Pact of August 1939, Germany and the Soviet Union had partitioned Poland and marked out their \"spheres of influence\" across Finland, Estonia, Latvia, Lithuania and Romania."
    }' 


[
    {
        "text": "World War II or the Second World War, often abbreviated as WWII or WW2, was a global war that lasted from 1939 to 1945.\n\nIt involved the vast majority of the world'''s countries—including all of the great powers—forming two opposing military alliances: the Allies and the Axis powers.\n\nIn a total war directly involving more than 100 million personnel from more than 30 countries, the major participants threw their entire economic, industrial, and scientific capabilities behind the war effort, blurring the distinction between civilian and military resources.\n\nAircraft played a major role in the conflict, enabling the strategic bombing of population centres and the only two uses of nuclear weapons in war.",
        "spanStart": 0,
        "spanEnd": 704
    },
    {
        "text": "World War II was by far the deadliest conflict in human history; it
    resulted in 70 to 85 million fatalities, a majority being civilians.\n\nTens of millions of people died due to genocides (including the Holocaust), starvation, massacres, and disease.\n\nIn the wake of the Axis defeat, Germany and Japan were occupied, and war crimes tribunals were conducted against German and Japanese leaders.",
        "spanStart": 704,
        "spanEnd": 1092
    },
    {
        "text": "The exact causes of World War II are debated, but contributing
    factors included the Second Italo-Ethiopian War, the Spanish Civil War, the Second Sino-Japanese War, the Soviet–Japanese border conflicts and rising European tensions since World War I. World War II is generally considered to have begun on 1 September 1939, when Nazi Germany, under Adolf Hitler, invaded Poland.\n\nThe United Kingdom and France subsequently declared war on Germany on 3 September.\n\nUnder the Molotov–Ribbentrop Pact of August 1939, Germany and the Soviet Union had partitioned Poland and marked out their "spheres of influence" across Finland, Estonia, Latvia, Lithuania and Romania.",
        "spanStart": 1092,
        "spanEnd": 1751
    }
]

Summarizing long texts slice-by-slice

The example below shows a typical flow for summarizing texts longer than Summarize APIs 10,000 character limit. First, we call Slice and get a list of slices. Second, we iterate through the list and perform a Summarize call to summarize each slice. We print the summaries in order to form a summary of the entire document.