Once Google Cloud project is set up and the Vertext AI API is enabled, you can use the Vertex AI REST API with cURL commands to interact with the Gemini 2.0 Flash model.

- Text generation
The `generateContent` method can handle a wide variety of cases including below.
- multi-turn chat
- multimodal input
Below example, you send a text prompt and request the model response in text.
%%bash
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${API_ENDPOINT}:generateContent \
-d '{
"contents": {
"role": "USER",
"parts": { "text": "Why is the sky blue?" },
},
"generation_config": {
"response_modalities": "TEXT",
},
}' 2>/dev/null >response.json
jq -r ".candidates[].content.parts[].text" response.json
- Streaming text generation
The Gemini API provides a streaming response mechanism. It's like you instantly get the answer from chat GPT when you ask a question in the prompt. You don't need to wait for the complete response.
%%bash
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${API_ENDPOINT}:streamGenerateContent \
\
-d '{
"contents": {
"role": "USER",
"parts": { "text": "Why is the sky blue?" }
}
}' 2>/dev/null >response.json
jq -r ".[] | .candidates[] | .content.parts[].text" response.json
- Chat
The Gemini API supports multi-turn conversations where user can get back-and-forth interactions with a model.
Specify the `role` field only if the content represents a turn in a conversation.
%%bash
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${API_ENDPOINT}:generateContent \
-d '{
"contents": [
{
"role": "user",
"parts": [
{ "text": "Hello" }
]
},
{
"role": "model",
"parts": [
{ "text": "Hello! I am glad you could both make it." }
]
},
{
"role": "user",
"parts": [
{ "text": "So what is the first order of business?" }
]
}
]
}' 2>/dev/null >response.json
jq -r ".candidates[].content.parts[].text" response.json
- Function Calling
When you ask a question or command to a model, function calling creates a description of a function in ther code, then pass that description to a language model.
%%bash
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json" \
https://${API_ENDPOINT}:generateContent \
-d '{
"contents": {
"role": "user",
"parts": {
"text": "Which theaters in Mountain View show Barbie movie?"
}
},
"tools": [
{
"function_declarations": [
{
"name": "find_movies",
"description": "find movie titles currently playing in theaters based on any description, genre, title words, etc.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
},
"description": {
"type": "string",
"description": "Any kind of description including category or genre, title words, attributes, etc."
}
},
"required": [
"description"
]
}
},
{
"name": "find_theaters",
"description": "find theaters based on location and optionally movie title which are is currently playing in theaters",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
},
"movie": {
"type": "string",
"description": "Any movie title"
}
},
"required": [
"location"
]
}
},
{
"name": "get_showtimes",
"description": "Find the start times for movies playing in a specific theater",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA or a zip code e.g. 95616"
},
"movie": {
"type": "string",
"description": "Any movie title"
},
"theater": {
"type": "string",
"description": "Name of theater"
},
"date": {
"type": "string",
"description": "Date for requested showtime"
}
},
"required": [
"location",
"movie",
"theater",
"date"
]
}
}
]
}
]
}' 2>/dev/null >response.json
jq -r ".candidates[].content.parts[].functionCall" response.json
- Multimodal Input
Gemin supports adding image and video in chat prompts.
Ref
Gemini for Google Cloud Learning Path > Course > Develop GenAI Apps with Gemini and Streamlit
'Google Cloud Platform' 카테고리의 다른 글
| Explore Generative AI with the Gemini API in Vertex AI: Challenge Lab (0) | 2025.09.24 |
|---|---|
| Build a Website on Google Cloud: Challenge Lab (1) | 2025.09.11 |
| Set Up a Google Cloud Network (2) | 2025.08.23 |
| Develop GenAI Apps with Gemini and Streamlit | feat. WebSocket error (0) | 2025.08.18 |
| Introduction to Function Calling with Gemini (0) | 2025.08.11 |