:::card{title="Deepgram API Playground" href="https://playground.deepgram.com/?endpoint=read&summarize=v2&topics=true&intents=true&sentiment=true&language=en"}
Try this feature out in our API Playground.
:::

In this guide, you’ll learn how to analyze text using Deepgram’s text intelligence features: Summarization, Topic Detection, Intent Recognition, and Sentiment Analysis. The code examples use [Deepgram’s SDKs](/guides/home-home).

:::callout{intent="info"}
Before you start, you’ll need to follow the steps in the [Make Your First API Request](/guides/guides-fundamentals-make-your-first-api-request) guide to obtain a Deepgram API key, and configure your environment if you are choosing to use a Deepgram SDK.
:::

## Purpose

Text Intelligence analyzes text content using four types of analysis: [Summarization](/guides/self-hosted-deployments-6-text-summarization), [Topic Detection](/guides/self-hosted-deployments-6-text-topic-detection), [Intent Recognition](/guides/self-hosted-deployments-6-text-intention-recognition), and [Sentiment Analysis](/guides/self-hosted-deployments-6-text-sentiment-analysis). You can send text as a string, local file, or hosted URL to receive structured analysis results.

## Make the Request

A request made using one of the text intelligence features will follow the same form for each of the features; therefore, this guide will walk you through how to make one request, and you can use the feature(s) of your choice depending on which feature you want to use (Summarization, Topic Detection, Intent Recognition, or Sentiment Analysis).

### Choose a Text

A text source can be sent to Deepgram as text (a text string or local text file) or as a url (hosted text file). These are referred to as a **basic text request** (string of text such as `"This is a string of text."`) or a **basic url request** (a hosted url such as `https://YOUR_FILE_URL.txt`).

### Basic Text Request

This example shows how to analyze a **local text file** as your text source.

```javascript
const { DeepgramClient } = require("@deepgram/sdk");
const fs = require("fs");

// path to text file
const text = fs.readFileSync("text.txt").toString();

const analyzeText = async () => {
  // STEP 1: Create a Deepgram client using the API key
  const deepgram = new DeepgramClient({ apiKey: process.env.DEEPGRAM_API_KEY });

  // STEP 2: Call the analyze method with the text payload and options
  // STEP 3: Configure Deepgram options for text analysis
  const result = await deepgram.read.v1.text.analyze({
    language: "en",
    sentiment: true,
    // intents: true,
    // summarize: true,
    // topics: true,
    body: { text },
  });

  // STEP 4: Print the results
  console.dir(result, { depth: null });
};

analyzeText();
```

### Basic URL Request

This example shows how to analyze a **hosted url file** as your text source.

```javascript
const { DeepgramClient } = require("@deepgram/sdk");

const analyzeUrl = async () => {
  // STEP 1: Create a Deepgram client using the API key
  const deepgram = new DeepgramClient({ apiKey: process.env.DEEPGRAM_API_KEY });

  // STEP 2: Call the analyze method with the hosted url source and options
  // STEP 3: Configure Deepgram options for text analysis
  const result = await deepgram.read.v1.text.analyze({
    language: "en",
    sentiment: true,
    // intents: true,
    // summarize: true,
    // topics: true,
    body: { url: "https://static.deepgram.com/examples/aura.txt" },
  });

  // STEP 4: Print the results
  console.dir(result, { depth: null });
};

analyzeUrl();
```

### Start the Application

Run your application from the terminal.

```javascript
# Run your application using the file you created in the previous step
# Example: node index.js
node index.js
```

### See Results

Your results will appear in your shell.

## Analyze the Response

When the file is finished processing (often after only a few seconds), you’ll receive a JSON response:

```json
{
  "metadata": {
    "request_id": "aff28024-3006-49e2-b70d-aabff2c23655",
    "created": "2024-01-30T15:22:33.604Z",
    "language": "en",
    "summary_info": {
      "model_uuid": "67875a7f-c9c4-48a0-aa55-5bdb8a91c34a",
      "input_tokens": 107,
      "output_tokens": 63
    }
  },
  "results": {
    "summary": {
      "text": "The speaker discusses the advances in speech recognition and spoken language understanding, citing examples such as the development of new transformer architectures for dealing with conversational audio and the use of model research for accurate transcriptions. They also mention the use of novel transformer architectures for handling conversational audio and the challenges of natural language understanding."
    }
  }
}
```

Following are explanations of each of the example responses. Be sure to click the tabs in the code block above to view the example response for each text analysis feature.

### Summarization

In the `metadata` object, we see:

- `summary_info`: information about the model used and the input/output tokens. Summarization pricing is based on the number of input and output tokens. Read more at [deepgram.com/pricing](https://deepgram.com/pricing).

In the `results` object, we see:

- `summary`: the `text` property in this object gives you the summary of the text you requested to be analyzed.

### Topic Detection

In the `metadata` object, we see:

- `topics_info`: information about the model used and the input/output tokens. Topic Detection pricing is based on the number of input and output tokens. Read more at [deepgram.com/pricing](https://deepgram.com/pricing).

In the `results` object, we see:

- `topics`(object): contains the data about Topic Detection.

- `segments`: each segment object contains a span of text taken from the input text; this `text` segment is analyzed for its topic.

- `topics`(array): a list of topic objects, each containing the `topic` and a `confidence_score`.

  - `topic`: Deepgram analyzes the segmented text to identify the main topic of each.
  - `confidence_score`: a floating point value between 0 and 1 indicating the overall reliability of the analysis.

### Intent Recognition

In the `metadata` object, we see:

- `intents_info`: information about the model used and the input/output tokens. Intent Recognition pricing is based on the number of input and output tokens. Read more at [deepgram.com/pricing](https://deepgram.com/pricing).

In the `results` object, we see:

- `intents`(object): contains the data about Intent Recognition.

- `segments`: each segment object contains a span of text taken from the input text; this `text` segment is analyzed for its intent.

- `intents`(array): a list of intent objects, each containing the `intent` and a `confidence_score`.

  - `intent`: Deepgram analyzes the segmented text to identify the intent of each.
  - `confidence_score`: a floating point value between 0 and 1 indicating the overall reliability of the analysis.

### Sentiment Analysis

In the `metadata` object, we see:

- `sentiment_info`: information about the model used and the input/output tokens. Sentiment Analysis pricing is based on the number of input and output tokens. Read more at [deepgram.com/pricing](https://deepgram.com/pricing).

In the `results` object, we see:

- `sentiments`(object): contains the data about Sentiment Analysis.
- `segments`: each segment object contains a span of text taken from the input text; these segments of text show when the sentiment shifts throughout the text, and each one is analyzed for its sentiment.
- `sentiment` can be `positive`, `negative`, or `neutral`.
- `sentiment_score`: a floating point value between -1 and 1 representing the sentiment of the associated span of text, with -1 being the most negative sentiment, and 1 being the most positive sentiment.
- `average`: the average sentiment for the entire input text.

## Constraints

Here are a few constraints to keep in mind when making your request.

### Language

At this time, text analysis features only work for English language texts. You must add a language parameter and set it to English when you make a text analysis request.

```python
response = client.read.v1.text.analyze(
    request={"text": "Your text here"},
    language="en",
    summarize=True,
)
```

### Token Limit

The input token limit is 150K tokens. When that limit is exceeded, a `400` error will be thrown.

```json
{
  "err_code": "TOKEN_LIMIT_EXCEEDED",
  "err_msg": "Text input currently supports up to 150K tokens. Please revise your text input to fit within the defined token limit. For more information, please visit our API documentation.",
  "request_id": "XXXX"
}
```

## Related pages

- [Feature Overview](./self-hosted-deployments-6-text-intelligence-feature-overview.md)
- [Template Apps](./self-hosted-deployments-6-text-intelligence-template-apps.md)
- [Intent Recognition](./self-hosted-deployments-6-text-intention-recognition.md)
- [Sentiment Analysis](./self-hosted-deployments-6-text-sentiment-analysis.md)
- [Summarization](./self-hosted-deployments-6-text-summarization.md)
- [Topic Detection](./self-hosted-deployments-6-text-topic-detection.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
