Text Correction

Updated at:

This API performs spelling correction and light rewriting on text in search and recommendation scenarios. Common uses include normalizing non-standard search queries from buyers and fixing obvious spelling errors in machine-translated results. This API supports 14 languages and is a synchronous API.

Use cases

This API acts as a pre-processor within search and recommendation pipelines. It is not a general-purpose grammar or style checker. It specializes in the following scenarios:

  • Search query normalization: Corrects user inputs like "Hellw World" to "Hello World" to improve recall.

  • Post-translation processing: Corrects spelling mistakes in the output of a Text Translation call.

  • UGC cleaning: Corrects user-generated content, such as product titles or reviews, before indexing to prevent dirty data from polluting the index.

To identify the input language, call the Language Detection API or set the SourceLanguage parameter to auto. Auto-detection is limited to the 14 supported languages.

API

POST /ai/text/correction

Quick start

import json

data = json.dumps({
    "SourceText": "Hellw World",
    "SourceLanguage": "en"
})
result = make_signed_request("/ai/text/correction", data)

print(result["Data"]["CorrectedText"])  # "Hello World"

Request parameters

Parameter

Type

Required

Description

SourceText

String

Yes

The source text to correct.

SourceLanguage

String

Yes

The source language. The value must be one of the 14 supported language codes. You can also set this to auto for automatic language detection, which is limited to the 14 supported languages.

Response fields

Field

Type

Description

Code

String

The status code. A value of Success indicates a successful call. Other values indicate an error.

Success

Boolean

Indicates whether the API call was successful.

RequestId

String

The request ID.

Message

String

The error message (returned only when the call fails).

Data.CorrectedText

String

The corrected text. If no errors are found, the original text is returned.

Data.UsageMap.InputCharacterCount

Number

The number of characters in the input for this request. This value is used for billing.

Full example

Request example

{
  "SourceText": "Hellw World",
  "SourceLanguage": "en"
}

Response example

{
  "Code": "Success",
  "Message": "Success",
  "Success": true,
  "RequestId": "2157065A-D6C8-1F3E-A4D0-B1234567890",
  "Data": {
    "CorrectedText": "Hello World",
    "UsageMap": { "InputCharacterCount": 11 }
  }
}

Supported languages (14)

Text Correction supports 14 languages. For a complete list of languages and their codes, see the "Text Correction supported language directions (14)" section in Language Direction Mapping.

Recommendations

  • Use only in search and recommendation pipelines: This API is designed for search and recommendation scenarios and is not suitable for correcting spelling in general documents, long-form text, or code snippets.

  • Check for changes: If CorrectedText == SourceText, no correction was made, and you can skip downstream processing on the client.

  • Handle unsupported languages: Text in languages other than the 14 supported ones will not be corrected. We recommend calling the Language Detection API first to determine whether to use this service.

  • Combine with translation: For best results, chain the APIs in the following order: Language Detection → Text Correction → Text Translation. This three-step process can significantly improve the readability of machine-translated output.

Error codes

Error code

Trigger

InvalidParameter

SourceText is empty or SourceLanguage is not one of the 14 supported language codes.

InputContentBlocked

The input text triggers content moderation.

FreeQuotaExhausted

The trial quota is exhausted.

InternalError

An internal server error occurred. If this error persists, contact technical support with the RequestId.

For a complete list of error codes, see Error Codes.

Limitations

  • Call mode: Synchronous. For details on QPS and timeout limits, see our rate limit documentation.

  • Supported languages: 14 languages.

  • Billing: ¥18 per million characters, based on the InputCharacterCount. For more details, see the billing documentation.

Next steps