---
title: "Google Translate API: Text Translation as JSON"
description: "One GET call translates a string and returns translated_text as JSON for 1 credit. The parameters, 195 language codes, a real response and batch costs."
url: https://perceptlayer.com/blog/google-translate-api-json
---

[Blog](https://perceptlayer.com/blog) / [API guides](https://perceptlayer.com/blog/category/api-guides)

# Google Translate API: Text Translation as JSON

21 Nov 2026 Perceptlayer 7 min read

To translate text with Google Translate as JSON, call `GET /v1/google-translate/translate` with three required parameters: `source` (a language code or `auto`), `text` and `target`. The recorded call with `source=en`, `text=Hello` and `target=de` returned `{"translated_text": "Hallo"}`. Each successful call costs 1 credit and translates one string into one language. This guide covers the request, the language codes, the response, a cached batch translator in Python and what a localization job costs.

## Key takeaways

-   `GET /v1/google-translate/translate` takes three required parameters, `source`, `text` and `target`, and no optional ones; it costs 1 credit per successful call.
-   `source` accepts 196 values, `auto` plus 195 language codes; `target` accepts the same 195 codes but not `auto`.
-   The recorded response has a single field, `translated_text`; it shows no detected-language field, so don't build on one.
-   One call is one string into one language: 2,000 strings into 4 languages is 2,000 × 4 × 1 credit = 8,000 credits, inside the Starter pack's 10,000.
-   Cache by `(source, target, text)` so you never pay twice for a string you've already translated.

## What does the Google Translate endpoint return?

The Google Translate API on Perceptlayer has one endpoint. You send a string, the language it's in and the language you want, and you get the translated string back as JSON. It's a `GET` request, it costs 1 credit per successful call, and it has no optional parameters, so there is nothing to tune: every call is one string, one source language and one target language.

| Method | Path | Returns | Credits | Required | Optional |
| --- | --- | --- | --- | --- | --- |
| `GET` | `/v1/google-translate/translate` | The translated text | 1 | `source`, `text`, `target` | none |

The data is collected from publicly available sources and returned as found at the time of the call. This isn't Google's own developer product, and this guide makes no claims about that one. If you're weighing the two, read Google's own documentation and terms and compare limits, pricing and output yourself. The [Google Translate API page](https://perceptlayer.com/apis/google-translate) has the endpoint and a playground where you can run it with your key.

## How do you send a translation request?

Send a `GET` request to `https://api.perceptlayer.com/v1/google-translate/translate` with the three parameters in the query string and your key in the `X-API-Key` header. This is the request behind the recorded response in this guide. Keys start with `sk_live_`, and where you can't set a header, the key can go in the `api_key` query parameter instead.

```bash
curl "https://api.perceptlayer.com/v1/google-translate/translate?source=en&text=Hello&target=de" \
  -H "X-API-Key: $API_KEY"
```

Text with spaces, punctuation or non-ASCII characters has to be URL-encoded, because it travels in the query string. With cURL, `--get` and `--data-urlencode` do the encoding for you:

```bash
curl --get "https://api.perceptlayer.com/v1/google-translate/translate" \
  --data-urlencode "source=en" \
  --data-urlencode "target=fr" \
  --data-urlencode "text=Your order has shipped." \
  -H "X-API-Key: $API_KEY"
```

In Python, `requests` encodes a `params` dictionary the same way. The [authentication docs](https://docs.perceptlayer.com/authentication) cover both ways of sending the key, and the [requests and responses docs](https://docs.perceptlayer.com/requests) cover the request format in general.

### Which parameters does the endpoint take?

The endpoint takes exactly three parameters, all required. The table lists what the API documents about each; nothing else is documented, including a maximum length for `text`, so test long inputs in the playground before you depend on them.

| Parameter | Type | Required | Documented values |
| --- | --- | --- | --- |
| `source` | string | yes | `auto` or one of 195 language codes |
| `text` | string | yes | None documented |
| `target` | string | yes | One of the same 195 language codes; `auto` is not allowed |

The asymmetry matters. `source=auto` is allowed, so you can send text without knowing its language. `target` has no `auto`, because you always have to say which language you want back.

### Which language codes are accepted?

`source` and `target` share a list of 195 language codes, and `source` adds `auto`. Most are short codes such as `en`, `de`, `fr`, `es`, `ja`, `ko`, `ar` and `hi`. Some carry a region or script suffix, such as `zh-CN`, `zh-TW`, `fr-CA`, `pt-PT`, `ms-Arab`, `pa-Arab` and `mni-Mtei`, so `pt` and `pt-PT` are two separate values. The full list is on the [translate endpoint page](https://perceptlayer.com/apis/google-translate/translate).

A few pairs in the list look like aliases: `iw` and `he`, `jw` and `jv`, `tl` and `fil`. The API doesn't document whether each pair returns the same output, so pick one code per language and use it everywhere. That keeps your cache keys consistent too. A value that isn't in the list is a parameter error, which comes back as `invalid_parameters` (422) and costs nothing.

## What does a translation response contain?

The recorded response is one JSON object with one field, `translated_text`, holding the translated string. This is the full recorded body for `text=Hello`, `source=en`, `target=de`:

```json
{
  "translated_text": "Hallo"
}
```

That's all the recording shows. There is no detected source language, no confidence score and no alternative translations in it, so code should read `translated_text` and treat anything else as unknown. If you send `source=auto`, you won't learn from this recording which language was detected; if you need that, record the source language on your side before you call.

The credit cost isn't in the body either, but it's in the headers. Every successful response carries `X-Credits-Used` (what the call cost) and `X-Credits-Remaining` (your balance after it), plus `RateLimit-Remaining` and `RateLimit-Reset` for the current minute. Read those headers if a batch job needs to stop before the balance runs out.

## How do you translate a batch of strings in Python?

A batch translator loops over your strings and target languages, calls the endpoint once per pair, and stores each result. Because every call costs 1 credit, the most useful thing it can do is not repeat itself: a cache keyed on `(source, target, text)` means a string you translated last week is free this week. The script below uses `requests` and the standard library's `sqlite3` and `csv`, and reads only `translated_text`.

```python
import csv
import os
import sqlite3
import time

import requests

API_KEY = os.environ["API_KEY"]
URL = "https://api.perceptlayer.com/v1/google-translate/translate"
SOURCE = "en"
TARGETS = ["de", "fr", "es", "ja"]

db = sqlite3.connect("translations.db")
db.execute(
    "CREATE TABLE IF NOT EXISTS t (source TEXT, target TEXT, text TEXT, out TEXT, "
    "PRIMARY KEY (source, target, text))"
)

def translate(text, target, attempts=3):
    row = db.execute(
        "SELECT out FROM t WHERE source=? AND target=? AND text=?", (SOURCE, target, text)
    ).fetchone()
    if row:
        return row[0]
    for _ in range(attempts):
        r = requests.get(
            URL,
            params={"source": SOURCE, "text": text, "target": target},
            headers={"X-API-Key": API_KEY},
            timeout=60,
        )
        if r.status_code in (429, 503):
            time.sleep(int(r.headers.get("Retry-After", "5")))
            continue
        r.raise_for_status()
        out = r.json().get("translated_text")
        db.execute("INSERT INTO t VALUES (?, ?, ?, ?)", (SOURCE, target, text, out))
        db.commit()
        time.sleep(1)
        return out
    raise RuntimeError(f"gave up on {target}: {text[:40]}")

with open("strings.csv", newline="") as f:
    strings = [row[0] for row in csv.reader(f) if row]

with open("translated.csv", "w", newline="") as f:
    out = csv.writer(f)
    out.writerow(["text"] + TARGETS)
    for s in strings:
        out.writerow([s] + [translate(s, t) for t in TARGETS])
```

The one-second pause after each paid call keeps a free account within its 1 request a second; on a paid pack you can shorten it. Cached strings skip both the call and the pause. Run this against the [recorded call in the playground](https://perceptlayer.com/apis/google-translate) first and confirm the response shape matches before you translate a whole file.

### What should the script do with errors?

Every error returns an HTTP status and a JSON body with `code`, `message` and `request_id`, and costs nothing. Retry `rate_limited` (429) and `temporarily_unavailable` (503) after the seconds in `Retry-After`, as the script does. Treat `invalid_parameters` (422) as a bug: usually a language code that isn't in the list. `insufficient_credits` (402) means the balance has run out, and nothing more is debited. Requests have no idempotency key, so a client timeout can hide a call that succeeded and was billed; keep the timeout generous and let the cache absorb reruns. The [errors docs](https://docs.perceptlayer.com/errors) list every code.

## What does a translation job cost?

Every successful call costs 1 credit, and one call translates one string into one language. So the cost of a job is the number of unique strings times the number of target languages, minus whatever your cache already holds. Failed calls cost nothing and return `X-Credits-Used: 0`.

| Job | Arithmetic | Credits |
| --- | --- | --- |
| Try it out | 100 strings × 1 language × 1 credit | 100 |
| App UI strings | 500 strings × 5 languages × 1 credit | 2,500 |
| Product catalogue | 2,000 strings × 4 languages × 1 credit | 8,000 |
| Help centre | 5,000 strings × 8 languages × 1 credit | 40,000 |

The 100 free credits on signup cover the first row: 100 translations, enough to check output quality in the languages you care about. The next two fit the Starter pack's 10,000 credits, and the help centre fits the Build pack's 50,000. Purchased credits last 12 months, with no subscription. See [pricing](https://perceptlayer.com/pricing) for what credits cost and the [credits docs](https://docs.perceptlayer.com/credits) for how calls are debited.

Speed is set by the request rate, not the cost. A free account runs 1 request a second, so the 2,500-call UI job takes about 42 minutes. Paying accounts run at least 5 requests a second, which brings it under 9 minutes. The [rate limits docs](https://docs.perceptlayer.com/rate-limits) list the rate each pack includes.

## Can an AI agent call the translate endpoint?

Yes. The same key works through the MCP server at `https://perceptlayer.com/mcp`, which gives an agent three tools: `search_endpoints` and `get_endpoint` look up the catalogue for free, and `call_endpoint` runs an endpoint with its parameters and spends its credits only on success. An agent can look up the translate endpoint with `search_endpoints`, then call it with `source`, `text` and `target` like any other tool.

In Claude Code, one command adds the server:

```bash
claude mcp add --transport http perceptlayer https://perceptlayer.com/mcp --header "Authorization: Bearer $API_KEY"
```

`call_endpoint` reports the credits used and remaining with each result, so an agent that translates as part of a larger task can see what it's spending. The [AI agents docs](https://docs.perceptlayer.com/ai-agents) cover the setup for other clients.

To try it now, run `source=en`, `text=Hello`, `target=de` in the playground on the [translate endpoint page](https://perceptlayer.com/apis/google-translate/translate), then [get a free API key](https://perceptlayer.com/signup) and point the script at your own strings. More guides like this one are in [API guides](https://perceptlayer.com/blog/category/api-guides), and other search engine sources are on the [search engines APIs](https://perceptlayer.com/verticals/search) page.

## APIs in this post

-   [Google Translate **1 credit per call** · 1 endpoint](https://perceptlayer.com/apis/google-translate)

## Frequently asked questions

### Is this Google's official translation API?

No. It's a Perceptlayer endpoint that returns Google Translate output, collected from publicly available sources and returned as found at the time of the call. This guide makes no claims about Google's own developer offering, its quotas or its pricing. If you're choosing between the two, read Google's documentation and terms and compare them yourself.

### How much does one translation cost?

One successful call costs 1 credit and translates one string into one language. Translating 500 strings into 5 languages is 2,500 calls, or 2,500 credits. Failed calls cost nothing and return `X-Credits-Used: 0`. The 100 free credits on signup cover 100 translations. See the pricing page for what credits cost.

### Can I translate into several languages in one call?

No. `target` takes a single language code, and the endpoint has no optional parameters, so each call returns one translation. To translate a string into four languages, make four calls, which costs 4 credits. Cache each result by source, target and text so repeat runs don't pay again.

### Does the response say which language was detected?

Not in the recorded response. It contains only `translated_text`, and the recording used `source=en` rather than `auto`. Run a call with `source=auto` in the playground to see what comes back, and until then, don't build on a detected-language field. If you need the source language, record it on your side.

### Is there a limit on how much text I can send?

The API doesn't document a maximum length for `text`. Because the text goes in the query string, very long inputs are better split into sentences or paragraphs, which also caches better. Test your longest strings in the playground first. Account request rates apply: 1 request a second on a free account, at least 5 on a paid pack.

google translate translation localization language codes python

## More from the blog

1.  [API guides](https://perceptlayer.com/blog/category/api-guides) 26 Nov 2026 Perceptlayer 7 min read
    
    ## [Depop API: Resale Listings as JSON](https://perceptlayer.com/blog/depop-api-json)
    
    Search Depop listings as JSON with brand, condition, sizes and price.amount per item; the recorded jacket search had a total\_count of 6,815,522. 1 credit.
    
2.  [API guides](https://perceptlayer.com/blog/category/api-guides) 26 Nov 2026 Perceptlayer 7 min read
    
    ## [Similarweb API: Website Traffic Data as JSON](https://perceptlayer.com/blog/similarweb-api-json)
    
    Get Similarweb traffic estimates as JSON: visits, bounce\_rate, traffic\_sources, top\_countries and top\_keywords for a domain, at 1 credit a call.
    
3.  [API guides](https://perceptlayer.com/blog/category/api-guides) 26 Nov 2026 Perceptlayer 7 min read
    
    ## [StockTwits API: Symbol Streams as JSON](https://perceptlayer.com/blog/stocktwits-api-json)
    
    Three StockTwits endpoints as JSON: a symbol's message stream with sentiment and cursor, symbol search and trending symbols, each 1 credit a call.
