google-ai
The google-ai
provider supports the https://generativelanguage.googleapis.com/v1beta/models/{model_id}/generateContent
and https://generativelanguage.googleapis.com/v1beta/models/{model_id}/streamGenerateContent
endpoints.
The use of v1beta
rather than v1
aligns with the endpoint conventions established in Google’s SDKs and offers access to both the existing v1
models and additional models exclusive to v1beta
.
BAML will automatically pick streamGenerateContent
if you call the streaming interface.
Example:
The options are passed through directly to the API, barring a few. Here’s a shorthand of the options:
Non-forwarded options
Will be passed as the x-goog-api-key
header. Default: env.GOOGLE_API_KEY
x-goog-api-key: $api_key
The base URL for the API. Default: https://generativelanguage.googleapis.com/v1beta
The default role for any prompts that don’t specify a role. Default: user
We don’t have any checks for this field, you can pass any string you wish.
The model to use. Default: gemini-1.5-flash
We don’t have any checks for this field, you can pass any string you wish.
See the Google Model Docs for the latest models.
Additional headers to send with the request.
Example:
The role to use if the role is not in the allowed_roles. Default: "user"
usually, but some models like OpenAI’s gpt-4o
will use "system"
Picked the first role in allowed_roles
if not “user”, otherwise “user”.
Which roles should we forward to the API? Default: ["system", "user", "assistant"]
usually, but some models like OpenAI’s o1-mini
will use ["user", "assistant"]
When building prompts, any role not in this list will be set to the default_role
.
Which role metadata should we forward to the API? Default: []
For example you can set this to ["foo", "bar"]
to forward the cache policy to the API.
If you do not set allowed_role_metadata
, we will not forward any role metadata to the API even if it is set in the prompt.
Then in your prompt you can use something like:
You can use the playground to see the raw curl request to see what is being sent to the API.
Whether the internal LLM client should use the streaming API. Default: true
Then in your prompt you can use something like:
Forwarded options
BAML will auto construct this field for you from the prompt
For all other options, see the official Google Gemini API documentation.