🔔 AutoML API NodeJS Client is now available in Vertex AI. Please visitnode-js-aiplatformfor the new NodeJS Vertex AI client.
Vertex AI is our next generation AI Platform, with many new features that are unavailable in the current platform.
Migrate your resources to Vertex AI to get
the latest machine learning features, simplify end-to-end journeys, and productionize models with MLOps.
Cloud AutoML API client for Node.js
A comprehensive list of changes in each version may be found in
the CHANGELOG.
const automl = require('@google-cloud/automl');
const fs = require('fs');
// Create client for prediction service.
const client = new automl.PredictionServiceClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = `The GCLOUD_PROJECT string, e.g. "my-gcloud-project"`;
// const computeRegion = `region-name, e.g. "us-central1"`;
// const modelId = `id of the model, e.g. “ICN723541179344731436”`;
// const filePath = `local text file path of content to be classified, e.g. "./resources/flower.png"`;
// const scoreThreshold = `value between 0.0 and 1.0, e.g. "0.5"`;
// Get the full path of the model.
const modelFullId = client.modelPath(projectId, computeRegion, modelId);
// Read the file content for prediction.
const content = fs.readFileSync(filePath, 'base64');
const params = {};
if (scoreThreshold) {
params.score_threshold = scoreThreshold;
}
// Set the payload by giving the content and type of the file.
const payload = {};
payload.image = {imageBytes: content};
// params is additional domain-specific parameters.
// currently there is no additional parameters supported.
const [response] = await client.predict({
name: modelFullId,
payload: payload,
params: params,
});
console.log('Prediction results:');
response.payload.forEach(result => {
console.log(`Predicted class name: ${resuresultplayName}`);
console.log(`Predicted class score: ${resuresultssification.score}`);
});
Samples
Samples are in the samples/ directory. Each sample's README.md has instructions for running its sample.
Our client libraries follow the Node.js release schedule.
Libraries are compatible with all current active and maintenance versions of
Node.js.
If you are using an end-of-life version of Node.js, we recommend that you update
as soon as possible to an actively supported LTS version.
Google's client libraries support legacy versions of Node.js runtimes on a
best-efforts basis with the following warnings:
Legacy versions are not tested in continuous integration.
Some security patches and features cannot be backported.
Dependencies cannot be kept up-to-date.
Client libraries targeting some end-of-life versions of Node.js are available, and
can be installed through npm dist-tags.
The dist-tags follow the naming convention legacy-(version).
For example, npm install @google-cloud/automl@legacy-8 installs client libraries
for versions compatible with Node.js 8.
This library is considered to be stable. The code surface will not change in backwards-incompatible ways
unless absolutely necessary (e.g. because of critical security issues) or with
an extensive deprecation period. Issues and requests against stable libraries
are addressed with the highest priority.
Please note that this README.md, the samples/README.md,
and a variety of configuration files in this repository (including .nycrc and tsconfig.json)
are generated from a central template. To edit one of these files, make an edit
to its templates in
directory.
[[["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-07 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [4.0.1 (latest)](/nodejs/docs/reference/automl/latest)\n- [4.0.0](/nodejs/docs/reference/automl/4.0.0)\n- [3.1.2](/nodejs/docs/reference/automl/3.1.2)\n- [2.5.2](/nodejs/docs/reference/automl/2.5.2)\n- [2.4.5](/nodejs/docs/reference/automl/2.4.5) \n\n[Cloud AutoML: Node.js Client](https://github.com/googleapis/nodejs-automl)\n===========================================================================\n\n[](https://cloud.google.com/terms/launch-stages)\n[](https://www.npmjs.org/package/@google-cloud/automl)\n\n🔔 **AutoML API NodeJS Client is now available in Vertex AI. Please visit**\n[node-js-aiplatform](https://github.com/googleapis/nodejs-ai-platform) **for the new NodeJS Vertex AI client.**\nVertex AI is our next generation AI Platform, with many new features that are unavailable in the current platform.\n[Migrate your resources to Vertex AI](https://cloud.google.com/vertex-ai/docs/start/migrating-to-vertex-ai) to get\nthe latest machine learning features, simplify end-to-end journeys, and productionize models with MLOps.\n\nCloud AutoML API client for Node.js\n\nA comprehensive list of changes in each version may be found in\n[the CHANGELOG](https://github.com/googleapis/nodejs-automl/blob/main/CHANGELOG.md).\n\n- [Cloud AutoML Node.js Client API Reference](https://cloud.google.com/nodejs/docs/reference/automl/latest)\n- [Cloud AutoML Documentation](https://cloud.google.com/automl/docs/)\n- [github.com/googleapis/nodejs-automl](https://github.com/googleapis/nodejs-automl)\n\nRead more about the client libraries for Cloud APIs, including the older\nGoogle APIs Client Libraries, in [Client Libraries Explained](https://cloud.google.com/apis/docs/client-libraries-explained).\n\n**Table of contents:**\n\n- [Quickstart](#quickstart)\n - [Before you begin](#before-you-begin)\n - [Installing the client library](#installing-the-client-library)\n - [Using the client library](#using-the-client-library)\n- [Samples](#samples)\n- [Versioning](#versioning)\n- [Contributing](#contributing)\n- [License](#license)\n\nQuickstart\n----------\n\n### Before you begin\n\n1. [Select or create a Cloud Platform project](https://console.cloud.google.com/project).\n2. [Enable billing for your project](https://support.google.com/cloud/answer/6293499#enable-billing).\n3. [Enable the Cloud AutoML API](https://console.cloud.google.com/flows/enableapi?apiid=automl.googleapis.com).\n4. [Set up authentication with a service account](https://cloud.google.com/docs/authentication/getting-started) so you can access the API from your local workstation.\n\n### Installing the client library\n\n npm install @google-cloud/automl\n\n### Using the client library\n\n const automl = require('https://cloud.google.com/nodejs/docs/reference/automl/latest/overview.html');\n const fs = require('fs');\n\n // Create client for prediction service.\n const client = new automl.https://cloud.google.com/nodejs/docs/reference/automl/latest/overview.html();\n\n /**\n * TODO(developer): Uncomment the following line before running the sample.\n */\n // const projectId = `The GCLOUD_PROJECT string, e.g. \"my-gcloud-project\"`;\n // const computeRegion = `region-name, e.g. \"us-central1\"`;\n // const modelId = `id of the model, e.g. \"ICN723541179344731436\"`;\n // const filePath = `local text file path of content to be classified, e.g. \"./resources/flower.png\"`;\n // const scoreThreshold = `value between 0.0 and 1.0, e.g. \"0.5\"`;\n\n // Get the full path of the model.\n const modelFullId = client.modelPath(projectId, computeRegion, modelId);\n\n // Read the file content for prediction.\n const content = fs.readFileSync(filePath, 'base64');\n\n const params = {};\n\n if (scoreThreshold) {\n params.score_threshold = scoreThreshold;\n }\n\n // Set the payload by giving the content and type of the file.\n const payload = {};\n payload.image = {imageBytes: content};\n\n // params is additional domain-specific parameters.\n // currently there is no additional parameters supported.\n const [response] = await client.predict({\n name: modelFullId,\n payload: payload,\n params: params,\n });\n console.log('Prediction results:');\n response.payload.forEach(result =\u003e {\n console.log(`Predicted class name: ${resuhttps://cloud.google.com/nodejs/docs/reference/automl/latest/automl/protos.google.longrunning.operation.htmlplayName}`);\n console.log(`Predicted class score: ${resuhttps://cloud.google.com/nodejs/docs/reference/automl/latest/automl/protos.google.longrunning.operation.htmlssification.score}`);\n });\n\nSamples\n-------\n\nSamples are in the [`samples/`](https://github.com/googleapis/nodejs-automl/tree/main/samples) directory. Each sample's `README.md` has instructions for running its sample.\n\nThe [Cloud AutoML Node.js Client API Reference](https://cloud.google.com/nodejs/docs/reference/automl/latest) documentation\nalso contains samples.\n\nSupported Node.js Versions\n--------------------------\n\nOur client libraries follow the [Node.js release schedule](https://github.com/nodejs/release#release-schedule).\nLibraries are compatible with all current *active* and *maintenance* versions of\nNode.js.\nIf you are using an end-of-life version of Node.js, we recommend that you update\nas soon as possible to an actively supported LTS version.\n\nGoogle's client libraries support legacy versions of Node.js runtimes on a\nbest-efforts basis with the following warnings:\n\n- Legacy versions are not tested in continuous integration.\n- Some security patches and features cannot be backported.\n- Dependencies cannot be kept up-to-date.\n\nClient libraries targeting some end-of-life versions of Node.js are available, and\ncan be installed through npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).\nThe dist-tags follow the naming convention `legacy-(version)`.\nFor example, `npm install @google-cloud/automl@legacy-8` installs client libraries\nfor versions compatible with Node.js 8.\n\nVersioning\n----------\n\nThis library follows [Semantic Versioning](http://semver.org/).\n\nThis library is considered to be **stable** . The code surface will not change in backwards-incompatible ways\nunless absolutely necessary (e.g. because of critical security issues) or with\nan extensive deprecation period. Issues and requests against **stable** libraries\nare addressed with the highest priority.\n\nMore Information: [Google Cloud Platform Launch Stages](https://cloud.google.com/terms/launch-stages)\n\nContributing\n------------\n\nContributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-automl/blob/main/CONTRIBUTING.md).\n\nPlease note that this `README.md`, the `samples/README.md`,\nand a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`)\nare generated from a central template. To edit one of these files, make an edit\nto its templates in\n[directory](https://github.com/googleapis/synthtool).\n\nLicense\n-------\n\nApache Version 2.0\n\nSee [LICENSE](https://github.com/googleapis/nodejs-automl/blob/main/LICENSE)"]]