Google's Generative Language API enables seamless prototyping using the Gemini models. It lets you test and explore the capabilities of Gemini models without needing to set up complex infrastructure or manage model deployment. Google's browser based prototyping tool Google AI Studio uses the Generative Language API to enable browser-based prototyping with generative models.
With Vertex AI SDK for ABAP, you can use the Generative Language API—Gemini API to start your prototyping journey, directly from within your ABAP environment. You need an API key generated from Google AI Studio to access the Gemini models. You need to generate this API key only once.
Generate an API key
The API key that you generate from Google AI Studio provides a convenient way to authenticate to the Gemini API.
In Google AI Studio, create an API key:
Open the API keys page.
Click Create API key.
If populated, then read and acknowledge the legal notice, and then click Continue.
If populated, then read and acknowledge the safety setting reminder.
In the Create API key dialog, select one of the following options, as appropriate:
- Create API key in new project
- Create API key in existing project
Copy your key string and keep it secure. You need this API key to configure authentication to the Gemini API.
Copy the project number of the Google Cloud project where the API key is generated. You need this in a later step.
Set up authentication
To authenticate to Gemini API by using an API key, use one of the following methods:
- Authenticate by using an API key stored in SAP SSF
- Authenticate by using an API key through a custom authentication class
Authenticate by using an API key stored in SAP SSF
To keep your API key secure, you can store the generated API key in SAP SSF and configure a client key with the SSF authentication class. You can use this client key to access the Gemini API. For more information, see:
Authenticate by using an API key through a custom authentication class
Alternatively, you can create a custom authentication class to keep your API key and configure a client key with the custom authentication class.
In your SAP system, create a
Z
class by implementing the interface/GOOG/IF_AUTH
that is shipped with the ABAP SDK for Google Cloud:- In SAP GUI, execute the transaction code
SE24
. - In the Object type field, type a name such as
Z_TEST_GEMINI_API
, and then click Create. - Make sure that the Object type is Class, and then click OK.
- In the Description field, provide a description of the class
such as
Class for authentication to Google AI Studio
, and then save the class as a Local Object or in a Transport Request. - Open the Interfaces tab, add the interface
/GOOG/IF_AUTH
, and then press enter. - Open the Methods tab. Methods of the interface
/GOOG/IF_AUTH
are automatically implemented into theZ
class. - Double-click the method
/GOOG/IF_AUTH~GET_ACCESS_TOKEN
. In the method
/GOOG/IF_AUTH~GET_ACCESS_TOKEN
, add the following code:ev_auth_type = /goog/if_auth=>c_auth_type_apik_ssf. cv_token = 'API_KEY'. GET TIME STAMP FIELD ev_logtime.
Replace
API_KEY
with the API key that you generated in Google AI Studio.Activate your
Z
class.
- In SAP GUI, execute the transaction code
In the SAP system, create a client key configuration:
In SAP GUI, execute the transaction code
/GOOG/SDK_IMG
.Alternatively, execute the transaction code
SPRO
, and then click SAP Reference IMG.Click ABAP SDK for Google Cloud > Basic Settings > Configure Client Key.
Click New Entries.
Enter values for the following fields:
Field Description Google Cloud Key Name Specify a name of the client key configuration, such as TEST_GEMINI_API
.Google Cloud Service Account Name Leave this field blank. Google Cloud Scope Leave this field blank. Google Cloud Project Identifier Specify the project number of the Google Cloud project where the API key is stored. Command name Leave this field blank. Authorization Class Specify the Z
class that you created in the preceding step, such asZ_TEST_GEMINI_API
.Token Caching Leave this field blank.
Token Refresh Seconds Leave this field blank. Authorization Parameter 1 Leave this field blank. Authorization Parameter 2 Leave this field blank. Save the new entry.
Make a note of the client key. You use this client key for authentication.
Run the AI Studio demo
You can explore the Gemini API capabilities by using the AI studio demo shipped with the Vertex AI SDK for ABAP.
To run the AI Studio demo, perform the following steps:
In SAP GUI, execute the transaction code
/GOOG/SDK_IMG
.Alternatively, execute the transaction code
SPRO
, and then click SAP Reference IMG.Go to ABAP SDK for Google Cloud > Demos.
Open Vertex AI SDK: Demo: Prototyping with Generative Language API.
In the Client key field, enter the client key that you've created in the Set up authentication section.
In the Model ID field, enter the ID of the LLM model that you want to use, such as
gemini-1.5-flash
. For information about the available models, see Model variants.Optionally, provide the following generation parameters as appropriate:
- Max output tokens
- Response Mime type
- Temperature
- TopK
- TopP
For information about these model generation parameters, see Experiment with parameter values.
In the Enter system instructions field, provide a system instruction.
In the Enter prompt field, provide your input prompt.
Run the program. The Response from LLM area shows the generated output.
Prototype AI use cases using ABAP
You can build prototype SAP applications using the /GOOG/CL_GENERATIVELANGUAGE_V1
and /GOOG/CL_GENERATIVELANG_V1BETA
classes shipped with the SDK. You can invoke these
classes from your ABAP environment using the client Key that
you've created in the
Set up authentication section.
What's next
- Learn how to install and configure the Vertex AI SDK for ABAP.
- Explore the built-in Generative AI demo programs for SAP.
- Learn about Generative AI on Vertex AI for SAP.
- Ask your questions and discuss the Vertex AI SDK for ABAP with the community on Cloud Forums.