Use the gcloud command line tool to call the analyze-entities command
and use the --content flag to
specify the text to analyze.
gcloudmllanguageanalyze-entities--content="Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'."
Command-line
Use curl to make a POST request to the documents:analyzeEntities
method and provide the appropriate request body as shown in the following
example.
The example uses the gcloud auth application-default print-access-token
command to obtain an access token for the service account that you created
when you set up the project.
curl-XPOST\
-H"Authorization: Bearer "$(gcloudauthapplication-defaultprint-access-token)\
-H"Content-Type: application/json; charset=utf-8"\
"https://language.googleapis.com/v1/documents:analyzeEntities"\
--data"{ 'document':{ 'type':'PLAIN_TEXT', 'content':'Michelangelo Caravaggio, Italian painter, is known for \'The Calling of Saint Matthew\'.' }, 'encodingType':'UTF8'}"
You should see a response similar to the following:
{"entities":[{"name":"Michelangelo Caravaggio","type":"PERSON","metadata":{"wikipedia_url":"http://en.wikipedia.org/wiki/Caravaggio","mid":"/m/020bg"},"salience":0.83047235,"mentions":[{"text":{"content":"Michelangelo Caravaggio","beginOffset":0},"type":"PROPER"},{"text":{"content":"painter","beginOffset":33},"type":"COMMON"}]},{"name":"Italian","type":"LOCATION","metadata":{"mid":"/m/03rjj","wikipedia_url":"http://en.wikipedia.org/wiki/Italy"},"salience":0.13870546,"mentions":[{"text":{"content":"Italian","beginOffset":25},"type":"PROPER"}]},{"name":"The Calling of Saint Matthew","type":"EVENT","metadata":{"mid":"/m/085_p7","wikipedia_url":"http://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)"},"salience":0.030822212,"mentions":[{"text":{"content":"The Calling of Saint Matthew","beginOffset":69},"type":"PROPER"}]}],"language":"en"}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Quickstart: Perform sentiment analysis by using the gcloud tool\n\nPerform sentiment analysis by using the gcloud tool\n===================================================\n\nThis page shows you how to get started with the Cloud Natural Language API using the\nGoogle Cloud SDK.\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nGoogle Cloud console, click **Guide me**:\n\n[Guide me](https://console.cloud.google.com/freetrial?redirectPath=/home/dashboard?tutorial=natural-language__quickstart)\n\n*** ** * ** ***\n\nBefore you begin\n----------------\n\n- [Sign in](https://accounts.google.com/Login) to your Google Account.\n\n If you don't already have one, [sign up for a new account](https://accounts.google.com/SignUp).\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n- [Create or select a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects).\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n - Create a Google Cloud project:\n\n ```\n gcloud projects create PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with a name for the Google Cloud project you are creating.\n - Select the Google Cloud project that you created:\n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project name.\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Natural Language API:\n\n\n ```bash\n gcloud services enable language.googleapis.com\n ```\n\n-\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n- If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n-\n To [initialize](/sdk/docs/initializing) the gcloud CLI, run the following command:\n\n ```bash\n gcloud init\n ```\n- [Create or select a Google Cloud project](https://cloud.google.com/resource-manager/docs/creating-managing-projects).\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n - Create a Google Cloud project:\n\n ```\n gcloud projects create PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with a name for the Google Cloud project you are creating.\n - Select the Google Cloud project that you created:\n\n ```\n gcloud config set project PROJECT_ID\n ```\n\n Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your Google Cloud project name.\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Natural Language API:\n\n\n ```bash\n gcloud services enable language.googleapis.com\n ```\n\n\u003cbr /\u003e\n\nMake an entity analysis request\n-------------------------------\n\n### gcloud\n\nUse the `gcloud` command line tool to call the `analyze-entities` command and use the `--content` flag to specify the text to analyze. \n\n gcloud ml language analyze-entities --content=\"Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'.\"\n\n### Command-line\n\nUse `curl` to make a `POST` request to the `documents:analyzeEntities` method and provide the appropriate request body as shown in the following example.\n\n\u003cbr /\u003e\n\nThe example uses the `gcloud auth application-default print-access-token`\ncommand to obtain an access token for the service account that you created\nwhen you set up the project. \n\n```bash\ncurl -X POST \\\n -H \"Authorization: Bearer \"$(gcloud auth application-default print-access-token) \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n \"https://language.googleapis.com/v1/documents:analyzeEntities\" \\\n --data \"{\n 'document':{\n 'type':'PLAIN_TEXT',\n 'content':'Michelangelo Caravaggio, Italian painter, is known for\n \\'The Calling of Saint Matthew\\'.'\n },\n 'encodingType':'UTF8'\n}\"\n```\n\nYou should see a response similar to the following: \n\n```json\n{\n \"entities\": [\n {\n \"name\": \"Michelangelo Caravaggio\",\n \"type\": \"PERSON\",\n \"metadata\": {\n \"wikipedia_url\": \"http://en.wikipedia.org/wiki/Caravaggio\",\n \"mid\": \"/m/020bg\"\n },\n \"salience\": 0.83047235,\n \"mentions\": [\n {\n \"text\": {\n \"content\": \"Michelangelo Caravaggio\",\n \"beginOffset\": 0\n },\n \"type\": \"PROPER\"\n },\n {\n \"text\": {\n \"content\": \"painter\",\n \"beginOffset\": 33\n },\n \"type\": \"COMMON\"\n }\n ]\n },\n {\n \"name\": \"Italian\",\n \"type\": \"LOCATION\",\n \"metadata\": {\n \"mid\": \"/m/03rjj\",\n \"wikipedia_url\": \"http://en.wikipedia.org/wiki/Italy\"\n },\n \"salience\": 0.13870546,\n \"mentions\": [\n {\n \"text\": {\n \"content\": \"Italian\",\n \"beginOffset\": 25\n },\n \"type\": \"PROPER\"\n }\n ]\n },\n {\n \"name\": \"The Calling of Saint Matthew\",\n \"type\": \"EVENT\",\n \"metadata\": {\n \"mid\": \"/m/085_p7\",\n \"wikipedia_url\": \"http://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)\"\n },\n \"salience\": 0.030822212,\n \"mentions\": [\n {\n \"text\": {\n \"content\": \"The Calling of Saint Matthew\",\n \"beginOffset\": 69\n },\n \"type\": \"PROPER\"\n }\n ]\n }\n ],\n \"language\": \"en\"\n}\n```\n| You can also analyze document sentiment and extract syntax annotations from text by making requests to different Cloud Natural Language API endpoints. See the [Cloud Natural Language API\n| Basics](/natural-language/docs/basics) for more details.\n\nClean up\n--------\n\n| **Caution** : Deleting a project has the following effects:\n|\n| - **Everything in the project is deleted.** If you used an existing project for the tasks in this document, when you delete it, you also delete any other work you've done in the project.\n| - **Custom project IDs are lost.** When you created this project, you might have created a custom project ID that you want to use in the future. To preserve the URLs that use the project ID, such as an `appspot.com` URL, delete selected resources inside the project instead of deleting the whole project.\n|\n|\n| If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects\n| can help you avoid exceeding project quota limits.\n1. Delete a Google Cloud project: \n\n```\ngcloud projects delete PROJECT_ID\n```\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- Get started with the Natural Language API in your language of choice by using\n a [Cloud Natural Language Client Library](/natural-language/docs/reference/libraries).\n\n- Consult the [Natural Language Basics](/natural-language/docs/basics) for\n conceptual information on forming Natural Language API requests and handling\n responses.\n\n- Try the\n [Sentiment Analysis Tutorial](/natural-language/docs/sentiment-tutorial) and\n browse the [Sample Applications](/natural-language/docs/sample-apps)."]]