Google Translate API Usage Guide

If you need to automate translation tasks via API, the Google Translate API is a solid choice. Its translation quality may be slightly behind DeepL, but it offers better value—especially with 500,000 free characters every month.

Product Overview

Everyone has used Google Translate. Here we’re talking about its API service, officially called Google Cloud Translation. With the API you can do bulk translation, build custom models, translate documents, and more.

Product Overview

Pricing

500,000 characters free per month. Beyond that, you pay per character.

Price Chart

Basic vs Advanced

Feature Basic Advanced
Free Monthly Quota 500,000 500,000
Cost per 1 M chars $20 $80
Document Price $0.08 / pg $0.25 / pg
Custom Models

Getting Started

Create or Select a Project

  • Enable the API. If billing isn’t set up, you’ll be prompted to add a foreign-currency credit card.

Enable

Enable API

    $cred = gcloud auth print-access-token
    $project_id = "example"
    $headers = @{ "Authorization" = "Bearer $cred" }
    Invoke-WebRequest `
        -Method GET `
        -Headers $headers `
        -Uri "https://cloudresourcemanager.googleapis.com/v3/projects/${project_id}" | Select-Object -Expand Content
  • Quick test
    $cred = gcloud auth print-access-token
    $project_id = "example"
    $body = @{
        "sourceLanguageCode" = "en"
        "targetLanguageCode" = "zh"
        "contents" = @("Hello, world!")
        "mimeType" = "text/plain"
    }
    $body = $body | ConvertTo-Json
    $headers = @{
        "Authorization" = "Bearer $cred"
        "Content-Type" = "application/json; charset=utf-8"
        "x-goog-user-project" = $project_id
    }
    Invoke-WebRequest `
        -Method POST `
        -Headers $headers `
        -Uri "https://translation.googleapis.com/v3/projects/${project_id}:translateText" `
        -Body $body | Select-Object -Expand Content

Success

On Linux, use curl:

    export CRED=$(gcloud auth print-access-token)
    export PROJECT_ID="example"
    export SOURCE_LANGUAGE_CODE="en"
    export TARGET_LANGUAGE_CODE="zh"
    export CONTENTS="Hello, world!"
    export MIME_TYPE="text/plain"
    curl -X POST -H "Authorization: Bearer $CRED" -H "Content-Type: application/json; charset=utf-8" -H "x-goog-user-project: $PROJECT_ID" -d "{
        \"sourceLanguageCode\": \"$SOURCE_LANGUAGE_CODE\",
        \"targetLanguageCode\": \"$TARGET_LANGUAGE_CODE\",
        \"contents\": [\"$CONTENTS\"],
        \"mimeType\": \"$MIME_TYPE\"
    }" "https://translation.googleapis.com/v3/projects/$PROJECT_ID:translateText"

You now have everything you need to run bulk translations via the Google Translate API.

Common Use Cases

  • Translate websites or apps
  • Train custom translation models
  • Add multilingual subtitles to videos
  • Provide multilingual voiceovers
  • Translate richly formatted documents
  • Translate customer interactions in real time

Further Reading

Closing Notes

Google’s official documentation can be verbose; there are often several ways to achieve the same goal. This guide picks the simplest and most recommended flow for typical users.

  • We used local authentication (gcloud CLI)
  • We relied on the REST API with Curl/Invoke-WebRequest
  • And we opted for the Advanced tier

Originally published at blog.jqknono.dev, reproduction without permission is prohibited.

Get Alibaba Cloud Edge Security Acceleration (ESA) for Free

Alibaba Cloud Edge Security Acceleration (ESA) is a comprehensive service that integrates CDN, edge security protection, and dynamic acceleration. It significantly boosts the speed and security of websites and applications.

This article briefly explains how to claim an ESA package at no cost through official channels.

The campaign is open to all Alibaba Cloud users who have completed account verification. Free service credits are awarded in exchange for sharing your experience.

  • Promotion period: Starts on July 7, 2025, and runs for the long term (check official announcements for the final end date).
  • Participation rules:
    1. Create Content: Publish a post or video recommending Alibaba Cloud ESA on any social platform or tech forum (e.g., Linux.do, V2EX, X.com (Twitter), Bilibili, personal blog, etc.).
      • Content Requirements: The post/video must be positive and include at least one ESA-related image (e.g., ESA console screenshot, speed-test comparison, official product promo graphic).
      • Mandatory Link: The exclusive ESA free-claim URL (http://s.tb.cn/e6.0DENEf) must appear in the content.
    2. Claim Your Reward: After publishing, submit the link to your post/video and your Alibaba Cloud account ID to the reward-assistant via direct message or by joining the official group chat.
    3. Review & Distribution: Once approved, you’ll receive a voucher for 1-month ESA Basic.

Tips:

  • Each social-media account can claim the voucher only once per week.
  • There’s no limit to total redemptions; just change platforms or create new content weekly.
  • High-quality, high-readership posts (e.g., in-depth reviews or usage reports) may earn upgraded vouchers as extra rewards.

Important Notes

Please read the following to ensure a smooth redemption and usage of your free service:

  1. Voucher Usage: The voucher can cover traffic exceeding the Basic plan quota or be applied toward purchasing or upgrading to higher-tier plans.
  2. Finding Your Account ID: Log in to the Alibaba Cloud console, click your avatar in the upper-right corner, and find your account ID in the pop-up menu.
  3. Voucher Validity: The vouchers issued are normally valid for 365 days.
  4. Event End: The ESA team will decide the final end date based on overall participation and will announce it in advance in the official documentation.

Real-World Results

The ESA international edition offers global coverage. Actual tests show promising speeds—esa-1almost everything is green.

esa-1