Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Pelaporan penggunaan dengan label (Lanjutan)
Cloud Translation API mendukung penambahan label yang ditentukan pengguna (key-value pair) ke permintaan TranslateText, BatchTranslateText, dan DetectLanguage.
Informasi tentang penggunaan permintaan diteruskan ke sistem penagihan, yang dapat Anda gunakan untuk memerinci biaya penagihan dengan memfilter berdasarkan label.
Kasus penggunaan
Kasus penggunaan penting untuk label melibatkan pelanggan yang menyediakan layanan
terjemahan kepada banyak klien. Satu project dapat digunakan untuk beberapa klien. Untuk tujuan penagihan, penting untuk mengaitkan permintaan tertentu dengan kliennya masing-masing. Di sinilah fungsi label. Saat melakukan panggilan atas nama klien, Anda memberi label permintaan dengan label khusus klien. Label ini kemudian tersedia untuk tujuan pemfilteran di bagian Reports di Google Cloud.
Persyaratan untuk label
Label yang diterapkan ke permintaan harus memenuhi persyaratan berikut:
Setiap permintaan dapat memiliki beberapa label, hingga maksimum 64 label.
Setiap label harus berupa pasangan nilai kunci.
Kunci memiliki panjang minimum 1 karakter dan panjang maksimum 63 karakter, serta tidak boleh kosong. Nilai boleh kosong, dan memiliki panjang maksimum 63 karakter.
Kunci dan nilai hanya berisi huruf kecil, karakter numerik,
garis bawah, dan tanda hubung. Semua karakter harus menggunakan encoding UTF-8, dan
karakter internasional diizinkan.
Bagian kunci label harus unik dalam satu permintaan (misalnya, {'country':'india'} boleh saja, tetapi {'country':'india','country':'sweden'} tidak diizinkan).
Kunci harus diawali dengan huruf kecil atau karakter internasional.
Label dan penagihan
Di Cloud Translation, Anda dapat menggunakan label untuk mengatur biaya berdasarkan akun penagihan. Penggunaan label Cloud Translation tidak berubah.
Biaya terkait dengan akun penagihan project yang berisi
permintaan. Atau, jika model Terjemahan Mesin Neural (NMT) atau khusus digunakan, biaya akan dikaitkan dengan project yang berisi model tersebut.
Untuk tujuan penagihan, semua permintaan yang dapat ditagih dapat memiliki labelnya sendiri. Permintaan
yang dapat ditagih ini mencakup terjemahan batch, mendeteksi bahasa, dan menerjemahkan
teks.
Membuat dan mengelola label menggunakan API Cloud Translation
Gunakan Cloud Translation API untuk menambahkan label ke permintaan.
REST
Pada contoh berikut, label {'country':'russia'},{'env':'test'} ditambahkan
ke permintaan translateText.
Sebelum menggunakan salah satu data permintaan,
lakukan penggantian berikut:
PROJECT_NUMBER_OR_ID: ID numerik atau alfanumerik untuk project Google Cloud Anda
Metode HTTP dan URL:
POST https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID:translateText
Buka tampilan Laporan konsol penagihan Google Cloud untuk menggunakan label ini sebagai filter untuk penggunaan permintaan.
Dari dasbor, klik ikon tiga garis di sisi kiri atas dan pilih "Penagihan"
dari menu drop-down. Jika Anda memiliki beberapa akun penagihan, akan muncul halaman
yang meminta Anda untuk memilih. Klik "Buka akun penagihan tertaut".
Dari halaman Penagihan, pilih Reports di navigasi sebelah kiri.
Gunakan filter di navigasi sebelah kanan untuk memeriksa penggunaan permintaan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-04 UTC."],[],[],null,["# Reporting usage with labels (Advanced)\n======================================\n\nThe Cloud Translation API supports adding user-defined labels (key-value pairs)\nto `TranslateText`, `BatchTranslateText` and `DetectLanguage` requests.\nInformation about a request's usage is forwarded to the billing system where\nyou can break down your billing charges by filtering by label.\n\nUse case\n--------\n\nAn important use case for labels involves customers who provide translation\nservices to many clients. A single project can be used for multiple clients. For\nbilling purposes it's important to associate specific requests with their\nrespective clients. That's where labels come in. When making a call on behalf of\na client, you label the request with a client specific label. These labels are\nthen available for filtering purposes in the **Reports** section of\nthe Google Cloud.\n\nRequirements for labels\n-----------------------\n\nThe labels applied to a request must meet the following requirements:\n\n- Each request can have multiple labels, up to a maximum of 64.\n- Each label must be a key-value pair.\n- Keys have a minimum length of 1 character and a maximum length of 63 characters, and cannot be empty. Values can be empty, and have a maximum length of 63 characters.\n- Keys and values contain only lowercase letters, numeric characters, underscores, and dashes. All characters must use UTF-8 encoding, and international characters are allowed.\n- The key portion of a label must be unique within a single request (for example, `{'country':'india'}` is fine, but `{'country':'india','country':'sweden'}` is not allowed).\n- Keys must start with a lowercase letter or international character.\n\nLabels and billing\n------------------\n\nIn Cloud Translation, you can use labels to organize [fees](/translate/pricing)\nby billing account. You aren't changed for the use of Cloud Translation\nlabels.\n\nFees are associated with the billing account of the project that contains the\nrequest. Or, if a custom or Neural Machine Translation (NMT) model is used, fees\nare associated with the [project that contains the\nmodel](/translate/pricing#charged-projects).\n\nFor billing purposes, all billable requests can have labels of their own. These\nbillable requests include batch translation, detect language, and translate\ntext.\n\nCreating and managing labels using the Cloud Translation API\n------------------------------------------------------------\n\nUse the Cloud Translation API to add labels to a request.\n\n\n### REST\n\nIn the following example, the labels `{'country':'russia'}`,`{'env':'test'}` are added to the `translateText` request.\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_NUMBER_OR_ID\u003c/var\u003e: the numeric or alphanumeric ID of your Google Cloud project\n\n\nHTTP method and URL:\n\n```\nPOST https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID:translateText\n```\n\n\nRequest JSON body:\n\n```\n{\n source_language_code: 'en',\n target_language_code: 'ru',\n contents: 'Dr. Watson, come here!',\n labels: {'country':'russia','env':'test'}\n}\n\n```\n\nTo send your request, expand one of these options:\n\n#### curl (Linux, macOS, or Cloud Shell)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\ncurl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"x-goog-user-project: PROJECT_NUMBER_OR_ID\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -d @request.json \\\n \"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID:translateText\"\n```\n\n#### PowerShell (Windows)\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\"; \"x-goog-user-project\" = \"PROJECT_NUMBER_OR_ID\" }\n\nInvoke-WebRequest `\n -Method POST `\n -Headers $headers `\n -ContentType: \"application/json; charset=utf-8\" `\n -InFile request.json `\n -Uri \"https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID:translateText\" | Select-Object -Expand Content\n```\n\nYou should receive a JSON response similar to the following:\n\n```\n{\n \"translations\": [\n {\n \"translatedText\": \"Доктор Ватсон, иди сюда!\"\n }\n ]\n}\n```\n\n\u003cbr /\u003e\n\nPricing report\n--------------\n\nGo to the [Google Cloud](https://console.cloud.google.com/billing)\nbilling console **Reports** view to use these labels as filters for request\nusage.\n\n1. From the dashboard, click the hamburger icon on the upper left-hand side and select \"Billing\" from the drop-down. If you have multiple billing accounts a page appears that asks you to make a selection. Click \"Go to linked billing account.\"\n2. From the Billing page, select **Reports** in the left-hand nav.\n3. Use the filters in the right-hand nav to check usage of requests."]]