This quickstart shows you how to get started with the Gemini API using the SDK of your choice.
Prerequisites
This quickstart assumes that you're familiar with running shell scripts.
To complete this quickstart, you must have curl installed in your shell environment.
Set up authentication
The easiest way to authenticate to the Gemini API is to configure an API key, as described in this section. If you need stricter access controls, you can use OAuth instead.
If you don't already have an API key, create one in Google AI Studio.
Get an API key from Google AI Studio
Then, configure your key.
It is strongly recommended that you do not check an API key into your version control system but assign it as an environment variable instead:
export GOOGLE_API_KEY=<YOUR_API_KEY>
Make your first request
Use the
generateContent
method
to generate text.
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d '{
"contents": [{
"parts":[{"text": "Write a story about a magic backpack."}]
}]
}' 2> /dev/null
What's next
Now that you're set up to make requests to the Gemini API, you can use the full range of Gemini API capabilities to build your apps and workflows. To get started with Gemini API capabilities, see the following guides:
For in-depth documentation of Gemini API methods and request parameters, see the guides in the API reference.