Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Creazione di report sull'utilizzo con etichette (avanzato)
L'API Cloud Translation supporta l'aggiunta di etichette definite dall'utente (coppie chiave-valore)
alle richieste TranslateText, BatchTranslateText e DetectLanguage.
Le informazioni sull'utilizzo di una richiesta vengono inoltrate al sistema di fatturazione, dove puoi suddividere i costi di fatturazione filtrando per etichetta.
Caso d'uso
Un caso d'uso importante per le etichette riguarda i clienti che forniscono servizi di traduzione a molti clienti. Un singolo progetto può essere utilizzato per più clienti. Ai fini della fatturazione, è importante associare richieste specifiche ai rispettivi clienti. È qui che entrano in gioco le etichette. Quando effettui una chiamata per conto di un cliente, etichetti la richiesta con un'etichetta specifica per il cliente. Queste etichette sono
poi disponibili per il filtraggio nella sezione Report di
Google Cloud.
Requisiti per le etichette
Le etichette applicate a una richiesta devono soddisfare i seguenti requisiti:
Ogni richiesta può avere più etichette, fino a un massimo di 64.
Ogni etichetta deve essere una coppia chiave-valore.
Le chiavi hanno una lunghezza minima di 1 carattere e una lunghezza massima di 63
caratteri e non possono essere vuote. I valori possono essere vuoti e avere una lunghezza massima di 63 caratteri.
Chiavi e valori contengono solo lettere minuscole, caratteri numerici,
trattini bassi e trattini. Tutti i caratteri devono utilizzare la codifica UTF-8 e
sono consentiti i caratteri internazionali.
La parte della chiave di un'etichetta deve essere univoca all'interno di una singola richiesta (ad esempio, {'country':'india'} va bene, ma {'country':'india','country':'sweden'} non è consentito).
Le chiavi devono iniziare con una lettera minuscola o un carattere internazionale.
Etichette e fatturazione
In Cloud Translation, puoi utilizzare le etichette per organizzare le tariffe
per account di fatturazione. Non ti viene addebitato alcun costo per l'utilizzo delle etichette Cloud Translation.
Le tariffe sono associate all'account di fatturazione del progetto che contiene la
richiesta. In alternativa, se viene utilizzato un modello personalizzato o di traduzione automatica neurale (NMT), le tariffe
sono associate al progetto che contiene il
modello.
Ai fini della fatturazione, tutte le richieste fatturabili possono avere etichette proprie. Queste
richieste fatturabili includono la traduzione batch, il rilevamento della lingua e la traduzione
del testo.
Creazione e gestione delle etichette utilizzando l'API Cloud Translation
Utilizza l'API Cloud Translation per aggiungere etichette a una richiesta.
REST
Nel seguente esempio, le etichette {'country':'russia'},{'env':'test'} vengono aggiunte
alla richiesta translateText.
Prima di utilizzare i dati della richiesta,
apporta le seguenti sostituzioni:
PROJECT_NUMBER_OR_ID: l'ID numerico o alfanumerico del tuo Google Cloud progetto
Metodo HTTP e URL:
POST https://translation.googleapis.com/v3/projects/PROJECT_NUMBER_OR_ID:translateText
Vai alla visualizzazione Google Cloud
Report della console di fatturazione per utilizzare queste etichette come filtri per l'utilizzo delle richieste.
Nel pannello, fai clic sull'icona a forma di hamburger in alto a sinistra e seleziona "Fatturazione"
dal menu a discesa. Se disponi di più account di fatturazione, viene visualizzata una pagina che
ti chiede di effettuare una selezione. Fai clic su "Vai all'account di fatturazione collegato".
Nella pagina Fatturazione, seleziona Report nel menu di navigazione a sinistra.
Utilizza i filtri nel riquadro di navigazione a destra per controllare l'utilizzo delle richieste.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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."]]