Quickstart: Using client libraries

This page shows you how to get started with the Vertex AI Agent Builder API in your favorite programming language.

Before you begin

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project : Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project : To create a project, you need the Project Creator ( roles/resourcemanager.projectCreator ), which contains the resourcemanager.projects.create permission. Learn how to grant roles .

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project .

  4. Enable the Vertex AI Agent Builder API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin ), which contains the serviceusage.services.enable permission. Learn how to grant roles .

    Enable the API

  5. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role ( roles/iam.serviceAccountCreator ). Learn how to grant roles .
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart .

    5. Click Create and continue .
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner .

    7. Click Continue .
    8. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  6. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys .
    3. Click Add key , and then click Create new key .
    4. Click Create . A JSON key file is downloaded to your computer.
    5. Click Close .
  7. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again.

  8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project : Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project : To create a project, you need the Project Creator ( roles/resourcemanager.projectCreator ), which contains the resourcemanager.projects.create permission. Learn how to grant roles .

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project .

  10. Enable the Vertex AI Agent Builder API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role ( roles/serviceusage.serviceUsageAdmin ), which contains the serviceusage.services.enable permission. Learn how to grant roles .

    Enable the API

  11. Create a service account:

    1. Ensure that you have the Create Service Accounts IAM role ( roles/iam.serviceAccountCreator ). Learn how to grant roles .
    2. In the Google Cloud console, go to the Create service account page.

      Go to Create service account
    3. Select your project.
    4. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

      In the Service account description field, enter a description. For example, Service account for quickstart .

    5. Click Create and continue .
    6. Grant the Project > Owner role to the service account.

      To grant the role, find the Select a role list, then select Project > Owner .

    7. Click Continue .
    8. Click Done to finish creating the service account.

      Do not close your browser window. You will use it in the next step.

  12. Create a service account key:

    1. In the Google Cloud console, click the email address for the service account that you created.
    2. Click Keys .
    3. Click Add key , and then click Create new key .
    4. Click Create . A JSON key file is downloaded to your computer.
    5. Click Close .
  13. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file that contains your credentials. This variable applies only to your current shell session, so if you open a new session, set the variable again.

Install the client library

C#

For more on setting up your C# development environment, refer to the C# Development Environment Setup Guide .

Install-Package Google.Cloud.PubSub.V1 -Pre

Go

go get cloud.google.com/go/pubsub

Java

For more on setting up your Java development environment, refer to the Java Development Environment Setup Guide .

If you are using Maven , add the following to your pom.xml file. For more information about BOMs, see The Google Cloud Platform Libraries BOM .

 <dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.70.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-pubsub</artifactId>
  </dependency>

</dependencies> 

If you are using Gradle , add the following to your dependencies:

 implementation platform('com.google.cloud:libraries-bom:26.71.0')

implementation 'com.google.cloud:google-cloud-pubsub' 

If you are using sbt , add the following to your dependencies:

 libraryDependencies += "com.google.cloud" % "google-cloud-pubsub" % "1.143.0" 

If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:

The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.

Node.js

For more on setting up your Node.js development environment, refer to the Node.js Development Environment Setup Guide .

npm install @google-cloud/pubsub

PHP

composer require google/cloud-pubsub

Python

For more on setting up your Python development environment, refer to the Python Development Environment Setup Guide .

pip install --upgrade google-cloud-pubsub

Ruby

For more on setting up your Ruby development environment, refer to the Ruby Development Environment Setup Guide .

gem install google-cloud-pubsub

Do something

Now you can use Vertex AI Agent Builder to do something. Run the following code to perform your first something:

C#

To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  using 
  
  Google.Cloud.PubSub.V1 
 
 ; 
 using 
  
  Grpc.Core 
 
 ; 
 using 
  
 System 
 ; 
 public 
  
 class 
  
 CreateTopicSample 
 { 
  
 public 
  
 Topic 
  
 CreateTopic 
 ( 
 string 
  
 projectId 
 , 
  
 string 
  
 topicId 
 ) 
  
 { 
  
  PublisherServiceApiClient 
 
  
 publisher 
  
 = 
  
  PublisherServiceApiClient 
 
 . 
  Create 
 
 (); 
  
 var 
  
 topicName 
  
 = 
  
  TopicName 
 
 . 
  FromProjectTopic 
 
 ( 
 projectId 
 , 
  
 topicId 
 ); 
  
  Topic 
 
  
 topic 
  
 = 
  
 null 
 ; 
  
 try 
  
 { 
  
 topic 
  
 = 
  
 publisher 
 . 
  CreateTopic 
 
 ( 
 topicName 
 ); 
  
 Console 
 . 
 WriteLine 
 ( 
 $"Topic {topic. Name 
} created." 
 ); 
  
 } 
  
 catch 
  
 ( 
  RpcException 
 
  
 e 
 ) 
  
 when 
  
 ( 
 e 
 . 
  Status 
 
 . 
  StatusCode 
 
  
 == 
  
  StatusCode 
 
 . 
  AlreadyExists 
 
 ) 
  
 { 
  
 Console 
 . 
 WriteLine 
 ( 
 $"Topic {topicName} already exists." 
 ); 
  
 } 
  
 return 
  
 topic 
 ; 
  
 } 
 } 
 

Go

To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  // Sample pubsub-quickstart creates a Google Cloud Pub/Sub topic. 
 package 
  
 main 
 import 
  
 ( 
  
 "context" 
  
 "fmt" 
  
 "log" 
  
 "cloud.google.com/go/pubsub/v2" 
  
 "cloud.google.com/go/pubsub/v2/apiv1/pubsubpb" 
 ) 
 func 
  
 main 
 () 
  
 { 
  
 ctx 
  
 := 
  
 context 
 . 
 Background 
 () 
  
 // Sets your Google Cloud Platform project ID. 
  
 projectID 
  
 := 
  
 "YOUR_PROJECT_ID" 
  
 // Creates a client. 
  
 client 
 , 
  
 err 
  
 := 
  
 pubsub 
 . 
 NewClient 
 ( 
 ctx 
 , 
  
 projectID 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 log 
 . 
 Fatalf 
 ( 
 "Failed to create client: %v" 
 , 
  
 err 
 ) 
  
 } 
  
 defer 
  
 client 
 . 
 Close 
 () 
  
 // Sets the id for the new topic. 
  
 topicID 
  
 := 
  
 "my-topic" 
  
 pbTopic 
  
 := 
  
& pubsubpb 
 . 
 Topic 
 { 
  
 Name 
 : 
  
 fmt 
 . 
 Sprintf 
 ( 
 "projects/%s/topics/%s" 
 , 
  
 projectID 
 , 
  
 topicID 
 ), 
  
 } 
  
 // Creates the new topic. 
  
 topic 
 , 
  
 err 
  
 := 
  
 client 
 . 
 TopicAdminClient 
 . 
 CreateTopic 
 ( 
 ctx 
 , 
  
 pbTopic 
 ) 
  
 if 
  
 err 
  
 != 
  
 nil 
  
 { 
  
 log 
 . 
 Fatalf 
 ( 
 "Failed to create topic: %v" 
 , 
  
 err 
 ) 
  
 } 
  
 fmt 
 . 
 Printf 
 ( 
 "Topic %v created.\n" 
 , 
  
 topic 
 ) 
 } 
 

Java

To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 com.google.cloud.pubsub.v1. TopicAdminClient 
 
 ; 
 import 
  
 com.google.pubsub.v1. Topic 
 
 ; 
 import 
  
 com.google.pubsub.v1. TopicName 
 
 ; 
 import 
  
 java.io.IOException 
 ; 
 public 
  
 class 
 CreateTopicExample 
  
 { 
  
 public 
  
 static 
  
 void 
  
 main 
 ( 
 String 
 ... 
  
 args 
 ) 
  
 throws 
  
 Exception 
  
 { 
  
 // TODO(developer): Replace these variables before running the sample. 
  
 String 
  
 projectId 
  
 = 
  
 "your-project-id" 
 ; 
  
 String 
  
 topicId 
  
 = 
  
 "your-topic-id" 
 ; 
  
 createTopicExample 
 ( 
 projectId 
 , 
  
 topicId 
 ); 
  
 } 
  
 public 
  
 static 
  
 void 
  
 createTopicExample 
 ( 
 String 
  
 projectId 
 , 
  
 String 
  
 topicId 
 ) 
  
 throws 
  
 IOException 
  
 { 
  
 try 
  
 ( 
  TopicAdminClient 
 
  
 topicAdminClient 
  
 = 
  
  TopicAdminClient 
 
 . 
 create 
 ()) 
  
 { 
  
  TopicName 
 
  
 topicName 
  
 = 
  
  TopicName 
 
 . 
 of 
 ( 
 projectId 
 , 
  
 topicId 
 ); 
  
  Topic 
 
  
 topic 
  
 = 
  
 topicAdminClient 
 . 
 createTopic 
 ( 
 topicName 
 ); 
  
 System 
 . 
 out 
 . 
 println 
 ( 
 "Created topic: " 
  
 + 
  
 topic 
 . 
  getName 
 
 ()); 
  
 } 
  
 } 
 } 
 

Node.js

To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  // Imports the Google Cloud client library 
 const 
  
 { 
 PubSub 
 } 
  
 = 
  
 require 
 ( 
 ' @google-cloud/pubsub 
' 
 ); 
 async 
  
 function 
  
 quickstart 
 ( 
  
 projectId 
  
 = 
  
 'your-project-id' 
 , 
  
 // Your Google Cloud Platform project ID 
  
 topicNameOrId 
  
 = 
  
 'my-topic' 
 , 
  
 // Name for the new topic to create 
  
 subscriptionName 
  
 = 
  
 'my-sub' 
 , 
  
 // Name for the new subscription to create 
 ) 
  
 { 
  
 // Instantiates a client 
  
 const 
  
 pubsub 
  
 = 
  
 new 
  
  PubSub 
 
 ({ 
 projectId 
 }); 
  
 // Creates a new topic 
  
 const 
  
 [ 
 topic 
 ] 
  
 = 
  
 await 
  
 pubsub 
 . 
 createTopic 
 ( 
 topicNameOrId 
 ); 
  
 console 
 . 
 log 
 ( 
 `Topic 
 ${ 
 topic 
 . 
 name 
 } 
 created.` 
 ); 
  
 // Creates a subscription on that new topic 
  
 const 
  
 [ 
 subscription 
 ] 
  
 = 
  
 await 
  
 topic 
 . 
 createSubscription 
 ( 
 subscriptionName 
 ); 
  
 // Receive callbacks for new messages on the subscription 
  
 subscripti on 
 
 . 
  on 
 
 ( 
 'message' 
 , 
  
 message 
  
 = 
>  
 { 
  
 console 
 . 
 log 
 ( 
 'Received message:' 
 , 
  
 message 
 . 
 data 
 . 
 toString 
 ()); 
  
 process 
 . 
 exit 
 ( 
 0 
 ); 
  
 }); 
  
 // Receive callbacks for errors on the subscription 
  
 subscripti on 
 
 . 
  on 
 
 ( 
 'error' 
 , 
  
 error 
  
 = 
>  
 { 
  
 console 
 . 
 error 
 ( 
 'Received error:' 
 , 
  
 error 
 ); 
  
 process 
 . 
 exit 
 ( 
 1 
 ); 
  
 }); 
  
 // Send a message to the topic 
  
 await 
  
 topic 
 . 
  publishMessage 
 
 ({ 
 data 
 : 
  
 Buffer 
 . 
  from 
 
 ( 
 'Test message!' 
 )}); 
 } 
 

PHP

To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  # Includes the autoloader for libraries installed with composer 
 require __DIR__ . '/vendor/autoload.php'; 
 # Imports the Google Cloud client library 
 use Google\Cloud\PubSub\PubSubClient; 
 # Your Google Cloud Platform project ID 
 $projectId = 'YOUR_PROJECT_ID'; 
 # Instantiates a client 
 $pubsub = new PubSubClient([ 
 'projectId' => $projectId 
 ]); 
 # The name for the new topic 
 $topicName = 'my-new-topic-2'; 
 # Creates the new topic 
 $topic = $pubsub->createTopic($topicName); 
 echo 'Topic ' . $topic->name() . ' created.'; 
 

Python

To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  from 
  
 google.cloud 
  
 import 
 pubsub_v1 
 # TODO(developer) 
 # project_id = "your-project-id" 
 # topic_id = "your-topic-id" 
 publisher 
 = 
 pubsub_v1 
 . 
  PublisherClient 
 
 () 
 topic_path 
 = 
 publisher 
 . 
 topic_path 
 ( 
 project_id 
 , 
 topic_id 
 ) 
 topic 
 = 
 publisher 
 . 
 create_topic 
 ( 
 request 
 = 
 { 
 "name" 
 : 
 topic_path 
 }) 
 print 
 ( 
 f 
 "Created topic: 
 { 
 topic 
 . 
 name 
 } 
 " 
 ) 
 

Ruby

To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  # Imports the Google Cloud client library 
 require 
  
 "google/cloud/pubsub" 
 # Instantiates a client 
 pubsub 
  
 = 
  
 Google 
 :: 
 Cloud 
 :: 
 PubSub 
 . 
 new 
 topic_admin 
  
 = 
  
 pubsub 
 . 
 topic_admin 
 # The name for the new topic 
 # topic_id = "your-topic-id" 
 # Creates the new topic 
 topic 
  
 = 
  
 topic_admin 
 . 
 create_topic 
  
 name 
 : 
  
 pubsub 
 . 
 topic_path 
 ( 
 topic_id 
 ) 
 puts 
  
 "Topic 
 #{ 
 topic 
 . 
 name 
 } 
 created." 
 
Congratulations! You've sent your first request to Vertex AI Agent Builder.

How did it go?

Clean up

To avoid incurring charges to your Google Account for the resources used in this quickstart:

What's next

Find out more about our Vertex AI Agent Builder API Client Libraries .

Design a Mobile Site
View Site in Mobile | Classic
Share by: