14
votes

I am using translate API to translate some texts in my page, those texts are large html formated texts, so I had to develop a function that splits these texts into smaller pieces less than 4500 characters (including html tags) to avoid the limit of 5000 characters per request, also I had to modify the Google PHP API to allow send requests via POST.

I have enabled the paid version of the api in Goole Developers Console, and changed the total quota to 50M of characters per day and 500 requests/second/urser.

Now I am translating the whole database of texts with a script, it works fine but at some random points I revive the error "(403) User Rate Limit Exceeded", and I have to wait some minutes to re-run the script because when reached the error the api is returning the same error over and over until I wait some time.

I don't know why it keeps returning the error if I don't pass the number of requests, it's like it has some kind of maximum chaaracters per each interval of time or something...

4
"limit on request characters per second" - cloud.google.com/translate/v2/faq#technicalatastrumf

4 Answers

10
votes

You probably exceed the quota limits you set before: this is either the daily billable or the limit on the request characters per second.

To change the usage limits or request an increase to your quota, do the following: 1. Go to the Google Developers Console "https://console.developers.google.com/". 2. Select a project. 3. On the left sidebar, expand APIs & auth. 4. Click APIs. 5. Click the name of an activated API you're interested in "i.e. The Translate API". 6. Near the top of the info page for the API, click Quota.

  • If you have the billing enabled, just click Quota and it will take you to the quota page where you can view and change the quota-related settings.

  • If not, clicking Quota shows information about any free quota and limits that apply to the Translate API.

2
votes

Google Developer Console has a rate limit of 10 requests per second, regardless of the settings or limits you may have changed.

You may be exceeding this limit.

I was unable to find any documentation around this, but could verify it myself with various API requests.

1
votes

You control the characters limitation but not the concurrency

You are either making more than 500 concurrent request/second or you are using another Google API that is hitting such concurrency limitation.

1
votes

The referer header is not set by default, but it is possible to add the headers to a request like so:

$result = $t->translate('Hola Mundo', [
    'restOptions' => [
        'headers' => [
            'referer' => 'https://your-uri.com'
        ]
    ]
]);

If it makes more sense for you to set the referer at the client level (so all requests flowing through the client receive the header), this is possible as well:

$client = new TranslateClient([
    'key' => 'my-api-key',
    'restOptions' => [
        'headers' => [
            'referer' => 'https://your-uri.com'
        ]
    ]
]);

This worked for me!

Reference