GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - googleapis/nodejs-agentplatform

BranchesTags
Open more actions menu

Latest commit

 

History

449 Commits
449 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.kokoro
.kokoro
 
 
src
src
 
 
system_test
system_test
 
 
test
test
 
 
vertexai
vertexai
 
 
.eslintignore
.eslintignore
 
 
.eslintrc.json
.eslintrc.json
 
 
.gitignore
.gitignore
 
 
.jsdoc.js
.jsdoc.js
 
 
.prettierignore
.prettierignore
 
 
.prettierrc.js
.prettierrc.js
 
 
.release-please-manifest.json
.release-please-manifest.json
 
 
.repo-metadata.json
.repo-metadata.json
 
 
.trampolinerc
.trampolinerc
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CODE_OF_CONDUCT.md
CODE_OF_CONDUCT.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
package.json
package.json
 
 
release-please-config.json
release-please-config.json
 
 
tsconfig.json
tsconfig.json
 
 

Repository files navigation

Gemini Enterprise Agent Platform SDK for Node.js quickstart

The Agent Platform SDK for Node.js lets you use the Gemini API to build AI-powered features and applications. Both TypeScript and JavaScript are supported.

For the latest list of available Gemini models on Agent Platform, see the Model information page in Agent Platform documentation.

Before you begin

  1. Make sure your node.js version is 22 or above.

  2. Select or create a Google Cloud project.

  3. Enable billing for your project.

  4. Enable the Agent Platform API.

  5. Install the gcloud CLI.

  6. Initialize the gcloud CLI.

  7. Create local authentication credentials for your user account:

    gcloud auth application-default login

A list of accepted authentication options are listed in GoogleAuthOptions interface of google-auth-library-node.js GitHub repo.

Install the SDK

Install the Agent Platform SDK for Node.js by running the following command:

npm install @google-cloud/agentplatform

Instantiate the Agent Platform client

First, import the Client class:

import { Client } from '@google-cloud/agentplatform';

Then instantiate a client:

const client: Client = new Client({
  project: 'my-cloud-project',
  location: 'my-cloud-location',
});

Prompts

First define your prompt as a JS object or Prompt object. Then call createVersion.

const prompt = {
  promptData: {
    contents: [{ parts: [{ text: 'Hello, {name}! How are you?' }] }],
    systemInstruction: { parts: [{ text: 'Please answer in a short sentence.' }] },
    variables: [
      { name: { text: 'Alice' } },
    ],
    model: 'gemini-2.5-flash',
  },
};

const promptResource = await client.prompts.createVersion({
  prompt: prompt,
});

Note that you can also use typed objects to define your prompt. Some of the types used to do this (Content, Part) are from the Gen AI SDK (@google/genai).

import { Prompt } from '@google-cloud/agentplatform';
import { Part, Content } from '@google/genai';

const prompt: Prompt = {
  promptData: {
    contents: [{ parts: [{ text: 'Hello, {name}! How are you?' } as Part] } as Content],
    systemInstruction: { parts: [{ text: 'Please answer in a short sentence.' } as Part] } as Content,
    variables: [
      { name: { text: 'Alice' } as Part },
    ],
    model: 'gemini-2.5-flash',
  },
};

const promptResource = await client.prompts.createVersion({
  prompt: prompt,
});

Retrieve a prompt by calling get() with the promptId.

const dataset = (promptResource as any)._dataset;
const promptId = dataset?.name?.split('/').pop() || 'YOUR_PROMPT_ID';

const retrievedPrompt = await client.prompts.get({
  promptId: promptId,
});

After creating or retrieving a prompt, you can call models.generateContent() with that prompt using the Gen AI SDK (@google/genai).

import { GoogleGenAI } from '@google/genai';

// Create a Client in the Gen AI SDK
const genaiClient = new GoogleGenAI({ vertexai: true, project: 'your-project', location: 'your-location' });

// Call generateContent() with the prompt
if (retrievedPrompt.promptData?.contents) {
  const response = await genaiClient.models.generateContent({
    model: retrievedPrompt.promptData.model || 'gemini-2.5-flash',
    contents: retrievedPrompt.promptData.contents,
    config: {
      systemInstruction: retrievedPrompt.promptData.systemInstruction,
      ...(retrievedPrompt.promptData.generationConfig || {}),
    },
  });
  console.log(response.text);
}

License

The contents of this repository are licensed under the Apache License, version 2.0.

About

No description, website, or topics provided.

Resources

Readme
Apache-2.0 license

Code of conduct

Code of conduct

Contributing

Contributing

Security policy

Security policy
Activity
Custom properties

Stars

182 stars

Watchers

14 watching

Forks

70 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.