Introduction

The IBM Watson™ Tone Analyzer service uses linguistic analysis to detect emotional and language tones in written text. The service can analyze tone at both the document and sentence levels. You can use the service to understand how your written communications are perceived and then to improve the tone of your communications. Businesses can use the service to learn the tone of their customers' communications and to respond to each customer appropriately, or to understand and improve their customer conversations.

Note: Request logging is disabled for the Tone Analyzer service. Regardless of whether you set the X-Watson-Learning-Opt-Out request header, the service does not log or retain data from requests and responses.

The code examples on this tab use the client library that is provided for Java.

Maven

<dependency>
  <groupId>com.ibm.watson.developer_cloud</groupId>
  <artifactId>java-sdk</artifactId>
  <version>6.11.0</version>
</dependency>

Gradle

compile 'com.ibm.watson.developer_cloud:java-sdk:6.11.0'

GitHub

The code examples on this tab use the client library that is provided for Node.js.

Installation

npm install --save watson-developer-cloud

GitHub

The code examples on this tab use the client library that is provided for Python.

Installation

pip install --upgrade "watson-developer-cloud>=2.5.1"

GitHub

The code examples on this tab use the client library that is provided for Ruby.

Installation

gem install ibm_watson

GitHub

The code examples on this tab use the client library that is provided for Go.

go get -u github.com/watson-developer-cloud/go-sdk/...

GitHub

Authentication

IBM Cloud is migrating to token-based Identity and Access Management (IAM) authentication.

  • With some service instances, you authenticate to the API by using IAM. You can pass either a bearer token in an Authorization header or an API key. Tokens support authenticated requests without embedding service credentials in every call. API keys use basic authentication. Learn more about IAM.

    If you pass in the apikey, the SDK manages the lifecycle of the tokens. If you pass a token, you maintain the token lifecycle. Learn more about IAM authentication with the SDK.

  • In other instances, you authenticate by providing the username and password for the service instance. For more information, see Service credentials for Watson services.

To find out which authentication to use, view the service credentials by clicking the service instance on the Dashboard.

The "username" and "password" in the service credentials are different from your IBM Cloud account IBMid and password.

IAM authentication. Replace {apikey} and {url} with your service credentials.

curl -u "apikey:{apikey}" "{url}/{method}"

Basic authentication. Replace {username}, {password}, and {url} with your service credentials.

curl -u "{username}:{password}" "{url}/{method}"

SDK managing the IAM token. Replace {apikey}, {version} and {url}.

IamOptions options = new IamOptions.Builder()
    .apiKey("{apikey}")
    .build();

ToneAnalyzer toneAnalyzer = new ToneAnalyzer("{version}", options);

toneAnalyzer.setEndPoint("{url}");

Basic authentication. Replace {username}, {password}, `, and{url}`. Use either of the two constructors.

ToneAnalyzer toneAnalyzer = new ToneAnalyzer(
    "{version}",
    "{username}",
    "{password}");

toneAnalyzer.setEndPoint("{url}");

or

ToneAnalyzer toneAnalyzer = new ToneAnalyzer("{version}");
toneAnalyzer.setUsernameAndPassword("{username}","{password}");

toneAnalyzer.setEndPoint("{url}");

SDK managing the IAM token. Replace {apikey}, {version} and {url}.

var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');

var toneAnalyzer = new ToneAnalyzerV3({
  version: '{version}',
  iam_apikey: '{apikey}',
  url: '{url}'
});

Basic authentication. Replace {username}, {password}, `, and{url}`.

var  = require('watson-developer-cloud/tone-analyzer/v3');

var toneAnalyzer = new ToneAnalyzerV3({
  version: '{version}',
  username: '{username}',
  password: '{password}',
  url: '{url}'
});

SDK managing the IAM token. Replace {apikey}, {version} and {url}.

from watson_developer_cloud import ToneAnalyzerV3

tone_analyzer = ToneAnalyzerV3(
    version='{version}',
    iam_apikey='{apikey}',
    url='{url}'
)

Basic authentication. Replace {username}, {password}, `, and{url}`.

from watson_developer_cloud import ToneAnalyzerV3

tone_analyzer = ToneAnalyzerV3(
    version='{version}',
    username='{username}',
    password='{password}',
    url='{url}'
)

SDK managing the IAM token. Replace {apikey}, {version} and {url}.

require "ibm_watson"

tone_analyzer = IBMWatson::ToneAnalyzerV3.new(
  version: "{version}",
  iam_apikey: "{apikey}",
  url:"{url}"
)

Basic authentication. Replace {username}, {password}, `, and{url}`.

require "ibm_watson"

tone_analyzer = IBMWatson::ToneAnalyzerV3.new(
  version: "{version}",
  username: "{username}",
  password: "{password}",
  url:"{url}"
)

SDK managing the IAM token. Replace {apikey}, {version} and {url}.

import "github.com/watson-developer-cloud/go-sdk/toneanalyzerv3"

toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(&toneanalyzerv3.ToneAnalyzerV3Options{
  Version: "{version}",
  IAMApiKey: "{apikey}",
  URL: "{url}",
})

Basic authentication. Replace {username}, {password}, `, and{url}`.

import "github.com/watson-developer-cloud/go-sdk/toneanalyzerv3"

toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(&toneanalyzerv3.ToneAnalyzerV3Options{
  Version: "{version}",
  Username: "{username}",
  Password: "{password}",
  URL: "{url}",
})

Service endpoint

The service endpoint is based on the location of the service instance. For example, when Tone Analyzer is hosted in Frankfurt, the base URL is https://gateway-fra.watsonplatform.net/tone-analyzer/api. The URL might also be different when you use IBM Cloud Dedicated.

To find out which URL to use, view the service credentials by clicking the service instance on the Dashboard.

Use that URL in your requests to Tone Analyzer.

Set the correct service URL by calling the setEndPoint() method of the service instance.

Set the correct service URL by calling the url parameter when you create the service instance.

Set the correct service URL by calling the url parameter when you create the service instance or by calling the set_url() method of the service instance.

Set the correct service URL by calling the url parameter when you create the service instance or by calling the url= method of the service instance.

Set the correct service URL by the URL parameter when you create the service instance or by calling the SetURL= method of the service instance.

Service endpoints by location:

  • Dallas: https://gateway.watsonplatform.net/tone-analyzer/api
  • Washington DC: https://gateway-wdc.watsonplatform.net/tone-analyzer/api
  • Frankfurt: https://gateway-fra.watsonplatform.net/tone-analyzer/api
  • Sydney: https://gateway-syd.watsonplatform.net/tone-analyzer/api
  • Tokyo: https://gateway-tok.watsonplatform.net/tone-analyzer/api
  • London: https://gateway-lon.watsonplatform.net/tone-analyzer/api

All locations might not support Tone Analyzer. For details, see Service availability.

Dallas API endpoint

https://gateway.watsonplatform.net/tone-analyzer/api

Your service instance might not use this URL

Default URL

https://gateway.watsonplatform.net/tone-analyzer/api

Example for the Washington DC location

ToneAnalyzer toneAnalyzer = new ToneAnalyzer("{version}");
toneAnalyzer.setEndPoint("https://gateway-wdc.watsonplatform.net/tone-analyzer/api");

Default URL

https://gateway.watsonplatform.net/tone-analyzer/api

Example for the Washington DC location

var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');

var toneAnalyzer = new ToneAnalyzerV3({
  version: '{version}',
  iam_apikey: '{apikey}',
  url: 'https://gateway-wdc.watsonplatform.net/tone-analyzer/api'
});

Default URL

https://gateway.watsonplatform.net/tone-analyzer/api

Examples for the Washington DC location in the constructor and after instantiation

tone_analyzer = ToneAnalyzerV3(
  version='{version}',
  iam_apikey='{apikey}',
  url='https://gateway-wdc.watsonplatform.net/tone-analyzer/api'
)

or

tone_analyzer.set_url('https://gateway-wdc.watsonplatform.net/tone-analyzer/api')

Default URL

https://gateway.watsonplatform.net/tone-analyzer/api

Examples for the Washington DC location in the constructor and after instantiation

tone_analyzer = IBMWatson::.new(
  version: "{version}",
  api_key: "{apikey}",
  url: "https://gateway-wdc.watsonplatform.net/tone-analyzer/api"
)

or

tone_analyzer.url = "https://gateway-wdc.watsonplatform.net/tone-analyzer/api"

Default URL

https://gateway.watsonplatform.net/tone-analyzer/api

Examples for the Washington DC location in the constructor and after instantiation

toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(&toneanalyzerv3.ToneAnalyzerV3Options{
  Version: "{version}",
  IAMApiKey: "{apikey}",
  URL: "https://gateway-wdc.watsonplatform.net/tone-analyzer/api",
})

or

toneAnalyzer.SetURL("https://gateway-wdc.watsonplatform.net/tone-analyzer/api")

Versioning

API requests require a version parameter that takes a date in the format version=YYYY-MM-DD. When we change the API in a backwards-incompatible way, we release a new version date.

Send the version parameter with every API request. The service uses the API version for the date you specify, or the most recent version before that date. Don't default to the current date. Instead, specify a date that matches a version that is compatible with your app, and don't change it until your app is ready for a later version.

Specify the version to use on API requests with the version parameter when you create the service instance. The service uses the API version for the date you specify, or the most recent version before that date. Don't default to the current date. Instead, specify a date that matches a version that is compatible with your app, and don't change it until your app is ready for a later version.

This documentation describes the current version of Tone Analyzer, 2017-09-21. In some cases, differences in earlier versions are noted in the descriptions of parameters and response models.

Error handling

The Tone Analyzer service uses standard HTTP response codes to indicate whether a method completed successfully. HTTP response codes in the 2xx range indicate success. A response in the 4xx range is some sort of failure, and a response in the 5xx range usually indicates an internal system error that cannot be resolved by the user. Response codes are listed with the method.

ErrorResponse

Name Description
code
integer
The HTTP response code.
sub_code
string
A service-specific error code.
error
string
General description of an error.
help
string
A URL to documentation explaining the cause and possibly solutions for the error.

The Java SDK generates an exception for any unsuccessful method invocation. All methods that accept an argument can also throw an IllegalArgumentException.

Exception Description
IllegalArgumentException An illegal argument was passed to the method.

When the Java SDK receives an error response from the Tone Analyzer service, it generates an exception from the com.ibm.watson.developer_cloud.service.exception package. All service exceptions contain the following fields:

Field Description
statusCode The HTTP response code returned.
message A message that describes the error.

When the Node SDK receives an error response from the Tone Analyzer service, it creates an Error object with information that describes the error that occurred. This error object is passed as the first parameter to the callback function for the method. The contents of the error object are as shown in the following table.

Error

Field Description
code The HTTP response code returned.
message A message that describes the error.

The Python SDK generates an exception for any unsuccessful method invocation. When the Python SDK receives an error response from the Tone Analyzer service, it generates a WatsonApiException that contains the following fields.

Field Description
code The HTTP response code returned.
message A message that describes the error.
info A dictionary of additional information about the error.

When the Ruby SDK receives an error response from the Tone Analyzer service, it generates a WatsonApiException that contains the following fields.

Field Description
code The HTTP response code returned.
message A message that describes the error.
info A dictionary of additional information about the error.

The Go SDK generates an error for any unsuccessful service instantiation and method invocation. You can check for the error immediately. The contents of the error object are as shown in the following table.

Error

Field Description
code The HTTP response code returned.
message A message that describes the error.

Example error handling

try {

    // Invoke a Tone Analyzer method
} catch (NotFoundException e) {

    // Handle Not Found (404) exception
} catch (RequestTooLargeException e) {

    // Handle Request Too Large (413) exception
} catch (ServiceResponseException e) {

    // Base class for all exceptions caused by error responses from the service
    System.out.println("Service returned status code " + e.getStatusCode() + ": " + e.getMessage());
}

Example error handling

toneAnalyzer.method(params,
  function (err, response) {
    // The error will be the first argument of the callback
    if (err.code == 404) {

      // Handle Not Found (404) error
    } else if (err.code == 413) {

      // Handle Request Too Large (413) error
    } else {
      console.log('Unexpected error: ', err.code);
      console.log('error:', err);
    }
  });

Example error handling

from watson_developer_cloud import WatsonApiException
try:
    # Invoke a Tone Analyzer method
except WatsonApiException as ex:
    print "Method failed with status code " + str(ex.code) + ": " + ex.message

Example error handling

require "ibm_watson"
begin
  # Invoke a Tone Analyzer method
rescue WatsonApiException => ex
  print "Method failed with status code #{ex.code}: #{ex.error}"
end

Example error handling

import "github.com/watson-developer-cloud/go-sdk/toneanalyzerv3"

// Instantiate a service
toneAnalyzer, toneAnalyzerErr := toneanalyzerv3.NewToneAnalyzerV3(&toneAnalyzerv3.ToneAnalyzerV3Options{})

// Check for error
if toneAnalyzerErr != nil {
  panic(toneAnalyzerErr)
}

// Call a method
response, responseErr := toneAnalyzer.methodName(&methodOptions)

// Check for error
if responseErr != nil {
  panic(responseErr)
}

Data handling

Additional headers

Some Watson services accept special parameters in headers that are passed with the request. You can pass request header parameters in all requests or in a single request to the service.

To pass header parameters with every request, use the setDefaultHeaders method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, use the addHeader method as a modifier on the request before you execute the request.

To pass header parameters with every request, specify the headers parameter when you create the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, use the headers method as a modifier on the request before you execute the request.

To pass header parameters with every request, specify the set_default_headers method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, include headers as a dict in the request.

To pass header parameters with every request, specify the add_default_headers method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, specify the headers method as a chainable method in the request.

To pass header parameters with every request, specify the SetDefaultHeaders method of the service object. See Data collection for an example use of this method.

To pass header parameters in a single request, specify the Headers as a map in the request.

Example header parameter in a request

ReturnType returnValue = toneAnalyzer.methodName(parameters)
        .addHeader("Custom-Header", "{header_value}")
        .execute();

Example header parameter in a request

toneAnalyzer.methodName({
  parameters,
  headers: {
    'Custom-Header': '{header_value}'
  }
},
  function (err, response) {
    if (err) {
      console.log('error:', err);
    } else {
      console.log(response);
    }
  }
);

Example header parameter in a request

response = toneAnalyzer.methodName(
    parameters,
    headers = {
        'Custom-Header': '{header_value}'
    })

Example header parameter in a request

response = tone_analyzer.headers(
  "Custom-Header" => "{header_value}"
).methodName(parameters)

Example header parameter in a request

response, _ := toneanalyzerv3.methodName(
  &methodOptions{
    Headers: map[string]string{
      "Accept": "application/json",
    },
  },
)

Response details

The Tone Analyzer service might return information to the application in response headers.

To access information in the response headers, use one of the request methods that returns details with the response: executeWithDetails(), enqueueWithDetails(), or rxWithDetails(). These methods return a Response<T> object, where T is the expected response model. Use the getResult() method to access the response object for the method, and use the getHeaders() method to access information in response headers.

Example request to access response headers

Response<ReturnType> response = toneAnalyzer.methodName(parameters)
        .executeWithDetails();
// Access response from methodName
ReturnType returnValue = response.getResult();
// Access information in response headers
Headers responseHeaders = response.getHeaders();

To access information in the response headers, specify the headers attribute on the third parameter (response) that is passed to the callback function.

Example request to access response headers

toneAnalyzer.methodName({
  parameters
},
  function (err, result, response) {
    if (err) {
      console.log('error:', err);
    } else {
      console.log(response.headers);
    }
  }
);

The return value from all service methods is a DetailedResponse object. To access information in the result object or response headers, use the following methods.

DetailedResponse

Method Description
get_result() Returns the response for the service-specific method.
get_headers() Returns the response header information.
get_status_code() Returns the HTTP status code.

Example request to access response headers

toneAnalyzer.set_detailed_response(True)
response = toneAnalyzer.methodName(parameters)
// Access response from methodName
print(json.dumps(response.get_result(), indent=2))
// Access information in response headers
print(response.get_headers())
// Access HTTP response status
print(response.get_status_code())

The return value from all service methods is a DetailedResponse object. To access information in the response object, use the following properties.

DetailedResponse

Property Description
result Returns the response for the service-specific method.
headers Returns the response header information.
status Returns the HTTP status code.

Example request to access response headers

response = tone_analyzer.methodName(parameters)
# Access response from methodName
print response.result
# Access information in response headers
print response.headers
# Access HTTP response status
print response.status

The return value from all service methods is a DetailedResponse object. To access information in the result object or response headers, use the following methods.

DetailedResponse

Method Description
GetResult() Returns the response for the service-specific method.
GetHeaders() Returns the response header information.
GetStatusCode() Returns the HTTP status code.

Example request to access response headers

import "github.com/watson-developer-cloud/go-sdk/core"
response, _ := toneanalyzerv3.methodName(&methodOptions{})

// Access result
core.PrettyPrint(response.GetResult(), "Result ")

// Access response headers
core.PrettyPrint(response.GetHeaders(), "Headers ")

// Access status code
core.PrettyPrint(response.GetStatusCode(), "Status Code ")

Data collection

Request logging is disabled for the Tone Analyzer service. Regardless of whether you set the X-Watson-Learning-Opt-Out request header, the service does not log or retain data from requests and responses.

Example request

curl -u "apikey:{apikey}" -H "X-Watson-Learning-Opt-Out: true" "{url}/{method}"

Example request

Map<String, String> headers = new HashMap<String, String>();
headers.put("X-Watson-Learning-Opt-Out", "true");

toneAnalyzer.setDefaultHeaders(headers);

Example request

var  = require('watson-developer-cloud/');

var toneAnalyzer = new ToneAnalyzerV3({
  version: '{version}',
  iam_apikey: '{apikey}',
  headers: {
    'X-Watson-Learning-Opt-Out': 'true'
  }
});

Example request

tone_analyzer.set_default_headers({'x-watson-learning-opt-out': "true"})

Example request

tone_analyzer.add_default_headers(headers: {"x-watson-learning-opt-out" => "true"})

Example request

import "net/http"

headers := http.Header{}
headers.Add("x-watson-learning-opt-out", "true")
toneanalyzerv3.Service.SetDefaultHeaders(headers)

Synchronous and asynchronous requests

The Java SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the ServiceCall interface.

  • To call a method synchronously, use the execute method of the ServiceCall interface. You can call the execute method directly from an instance of the service.
  • To call a method asynchronously, use the enqueue method of the ServiceCall interface to receive a callback when the response arrives. The ServiceCallback interface of the method's argument provides onResponse and onFailure methods that you override to handle the callback.

The Ruby SDK supports both synchronous (blocking) and asynchronous (non-blocking) execution of service methods. All service methods implement the Concurrent::Async module. When you use the synchronous/asynchronous methods, an IVar object is returned. You access the DetailedResponse object by calling ivar_object.value.

For more information about the Ivar object, see the IVar class docs.

  • To call a method synchronously, either call the method directly, or use the .await chainable method of the Concurrent::Async module.

    Calling a method directly (without .await) returns a DetailedResponse object.

  • To call a method asynchronously, use the .async chainable method of the Concurrent::Async module.

You can call the .await and .async methods directly from an instance of the service.

Example synchronous request

ReturnType returnValue = toneAnalyzer.method(parameters).execute();

Example asynchronous request

toneAnalyzer.method(parameters).enqueue(new ServiceCallback<ReturnType>() {
        @Override public void onResponse(ReturnType response) {
            . . .
        }
        @Override public void onFailure(Exception e) {
            . . .
        }
    });

Example synchronous request

response = tone_analyzer.method_name(parameters)

or

response = tone_analyzer.await.method_name(parameters)

Example asynchronous request

response = tone_analyzer.async.method_name(parameters)

Methods

Analyze general tone (GET)

Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in plain text format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.

Use this GET method to analyze smaller quantities of plain text content. Use the Analyze general tone POST method to analyze larger amounts of content in any of the available formats.

Per the HTTP specification, the default encoding for plain text is ISO-8859-1 (effectively, the ASCII character set). Include the charset parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8.

See also: Using the general-purpose endpoint.

GET /v3/tone
Request

Custom Headers

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

Query Parameters

  • Plain text input that contains the content to be analyzed. You must URL-encode the input.

  • The version of the API that you want to use as a date in the form YYYY-MM-DD; for example, specify 2017-09-21 for September 21, 2017 (the latest version).

    The date that you specify does not need to match a version of the service exactly; the service uses the version that is no later than the date you provide. If you specify a date that is earlier than 2016-05-19, the service uses that version of the API. If you specify a date that is in the future or otherwise later than the most recent version, the service uses the latest version.

    Constraints: matches regular expression ^\d{4}-\d{2}-\d{2}$

  • Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If true (the default), the service returns results for each sentence.

    Default: true

  • 2017-09-21: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.

    2016-05-19: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.

    Allowable values: [emotion,language,social]

Example requests
Response

Status Code

  • OK. The request succeeded. If the input is partially correct, the response can include warning or error fields with appropriate messages.

  • Bad Request. A required input parameter is null or a specified input parameter or header value is invalid or not supported.

  • Unauthorized. Access is denied due to invalid service credentials.

  • Not Found. A requested item or parameter does not exist.

  • Too Many Requests. The service is throttling your request because your IBM Cloud ID submitted more than 1200 requests per minute.

  • Internal Server Error. The service encountered an internal error.

Example responses

Analyze general tone

Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.

Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8. For text/html, the service removes HTML tags and analyzes only the textual content.

See also: Using the general-purpose endpoint.

Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.

Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8. For text/html, the service removes HTML tags and analyzes only the textual content.

See also: Using the general-purpose endpoint.

Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.

Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8. For text/html, the service removes HTML tags and analyzes only the textual content.

See also: Using the general-purpose endpoint.

Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.

Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8. For text/html, the service removes HTML tags and analyzes only the textual content.

See also: Using the general-purpose endpoint.

Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.

Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8. For text/html, the service removes HTML tags and analyzes only the textual content.

See also: Using the general-purpose endpoint.

Use the general purpose endpoint to analyze the tone of your input content. The service analyzes the content for emotional and language tones. The method always analyzes the tone of the full document; by default, it also analyzes the tone of each individual sentence of the content.

You can submit no more than 128 KB of total input content and no more than 1000 individual sentences in JSON, plain text, or HTML format. The service analyzes the first 1000 sentences for document-level analysis and only the first 100 sentences for sentence-level analysis.

Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8; per the HTTP specification, the default encoding for plain text and HTML is ISO-8859-1 (effectively, the ASCII character set). When specifying a content type of plain text or HTML, include the charset parameter to indicate the character encoding of the input text; for example: Content-Type: text/plain;charset=utf-8. For text/html, the service removes HTML tags and analyzes only the textual content.

See also: Using the general-purpose endpoint.

POST /v3/tone
(toneAnalyzer *ToneAnalyzerV3) Tone(toneOptions *ToneOptions) (*core.DetailedResponse, error)
ServiceCall<ToneAnalysis> tone(ToneOptions toneOptions)
tone(params, callback())
tone(self, tone_input, content_type=None, sentences=None, tones=None, content_language=None, accept_language=None, **kwargs)
tone(tone_input:, content_type: nil, sentences: nil, tones: nil, content_language: nil, accept_language: nil)
Request

Use the ToneOptions.Builder to create a ToneOptions object that contains the parameter values for the tone method.

Custom Headers

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

  • Allowable values: [application/json,text/plain,text/html]

Query Parameters

  • The version of the API that you want to use as a date in the form YYYY-MM-DD; for example, specify 2017-09-21 for September 21, 2017 (the latest version).

    The date that you specify does not need to match a version of the service exactly; the service uses the version that is no later than the date you provide. If you specify a date that is earlier than 2016-05-19, the service uses that version of the API. If you specify a date that is in the future or otherwise later than the most recent version, the service uses the latest version.

    Constraints: matches regular expression ^\d{4}-\d{2}-\d{2}$

  • Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If true (the default), the service returns results for each sentence.

    Default: true

  • 2017-09-21: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.

    2016-05-19: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.

    Allowable values: [emotion,language,social]

JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type ToneInput.

parameters

  • JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type ToneInput.

  • The type of the input. A character encoding can be specified by including a charset parameter. For example, 'text/plain;charset=utf-8'.

    Allowable values: [application/json,text/plain,text/html]

  • Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If true (the default), the service returns results for each sentence.

    Default: true

  • 2017-09-21: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.

    2016-05-19: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.

    Allowable values: [emotion,language,social]

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

The tone options.

The tone options.

parameters

  • JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type ToneInput.

  • The type of the input. A character encoding can be specified by including a charset parameter. For example, 'text/plain;charset=utf-8'.

    Allowable values: [application/json,text/plain,text/html]

  • Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If true (the default), the service returns results for each sentence.

    Default: true

  • 2017-09-21: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.

    2016-05-19: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.

    Allowable values: [emotion,language,social]

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

parameters

  • JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type ToneInput.

  • The type of the input. A character encoding can be specified by including a charset parameter. For example, 'text/plain;charset=utf-8'.

    Allowable values: [application/json,text/plain,text/html]

  • Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If true (the default), the service returns results for each sentence.

    Default: true

  • 2017-09-21: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.

    2016-05-19: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.

    Allowable values: [emotion,language,social]

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

parameters

  • JSON, plain text, or HTML input that contains the content to be analyzed. For JSON input, provide an object of type ToneInput.

  • The type of the input. A character encoding can be specified by including a charset parameter. For example, 'text/plain;charset=utf-8'.

    Allowable values: [application/json,text/plain,text/html]

  • Indicates whether the service is to return an analysis of each individual sentence in addition to its analysis of the full document. If true (the default), the service returns results for each sentence.

    Default: true

  • 2017-09-21: Deprecated. The service continues to accept the parameter for backward-compatibility, but the parameter no longer affects the response.

    2016-05-19: A comma-separated list of tones for which the service is to return its analysis of the input; the indicated tones apply both to the full document and to individual sentences of the document. You can specify one or more of the valid values. Omit the parameter to request results for all three tones.

    Allowable values: [emotion,language,social]

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

Example requests
Response

Status Code

  • OK. The request succeeded. If the input is partially correct, the response can include warning or error fields with appropriate messages.

  • Bad Request. A required input parameter is null or a specified input parameter or header value is invalid or not supported.

  • Unauthorized. Access is denied due to invalid service credentials.

  • Not Found. A requested item or parameter does not exist.

  • Too Many Requests. The service is throttling your request because your IBM Cloud ID submitted more than 1200 requests per minute.

  • Internal Server Error. The service encountered an internal error.

Example responses

Analyze customer engagement tone

Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.

If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.

See also: Using the customer-engagement endpoint.

Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.

If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.

See also: Using the customer-engagement endpoint.

Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.

If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.

See also: Using the customer-engagement endpoint.

Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.

If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.

See also: Using the customer-engagement endpoint.

Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.

If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.

See also: Using the customer-engagement endpoint.

Use the customer engagement endpoint to analyze the tone of customer service and customer support conversations. For each utterance of a conversation, the method reports the most prevalent subset of the following seven tones: sad, frustrated, satisfied, excited, polite, impolite, and sympathetic.

If you submit more than 50 utterances, the service returns a warning for the overall content and analyzes only the first 50 utterances. If you submit a single utterance that contains more than 500 characters, the service returns an error for that utterance and does not analyze the utterance. The request fails if all utterances have more than 500 characters. Per the JSON specification, the default character encoding for JSON content is effectively always UTF-8.

See also: Using the customer-engagement endpoint.

POST /v3/tone_chat
(toneAnalyzer *ToneAnalyzerV3) ToneChat(toneChatOptions *ToneChatOptions) (*core.DetailedResponse, error)
ServiceCall<UtteranceAnalyses> toneChat(ToneChatOptions toneChatOptions)
toneChat(params, callback())
tone_chat(self, utterances, content_language=None, accept_language=None, **kwargs)
tone_chat(utterances:, content_language: nil, accept_language: nil)
Request

Use the ToneChatOptions.Builder to create a ToneChatOptions object that contains the parameter values for the toneChat method.

Custom Headers

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

Query Parameters

  • The version of the API that you want to use as a date in the form YYYY-MM-DD; for example, specify 2017-09-21 for September 21, 2017 (the latest version).

    The date that you specify does not need to match a version of the service exactly; the service uses the version that is no later than the date you provide. If you specify a date that is earlier than 2016-05-19, the service uses that version of the API. If you specify a date that is in the future or otherwise later than the most recent version, the service uses the latest version.

    Constraints: matches regular expression ^\d{4}-\d{2}-\d{2}$

An object that contains the content to be analyzed.

parameters

  • An object that contains the content to be analyzed.

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

The toneChat options.

The toneChat options.

parameters

  • An array of Utterance objects that provides the input content that the service is to analyze.

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

parameters

  • An array of Utterance objects that provides the input content that the service is to analyze.

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

parameters

  • An array of Utterance objects that provides the input content that the service is to analyze.

  • The language of the input text for the request: English or French. Regional variants are treated as their parent language; for example, en-US is interpreted as en. The input content must match the specified language. Do not submit content that contains both languages. You can use different languages for Content-Language and Accept-Language.

    • 2017-09-21: Accepts en or fr.
    • 2016-05-19: Accepts only en.

    Allowable values: [en,fr]

    Default: en

  • The desired language of the response. For two-character arguments, regional variants are treated as their parent language; for example, en-US is interpreted as en. You can use different languages for Content-Language and Accept-Language.

    Allowable values: [ar,de,en,es,fr,it,ja,ko,pt-br,zh-cn,zh-tw]

    Default: en

Example requests
Response

Status Code

  • OK. The request succeeded. If the input is partially correct, the response can include warning or error fields with appropriate messages.

  • Bad Request. A required input parameter is null or a specified input parameter or header value is invalid or not supported. The response is also returned if all utterances of the input have more than 500 characters.

  • Unauthorized. Access is denied due to invalid service credentials.

  • Not Found. A requested item or parameter does not exist.

  • Too Many Requests. The service is throttling your request because your IBM Cloud ID submitted more than 1200 requests per minute.

  • Internal Server Error. The service encountered an internal error.

Example responses