module

AI::Google

Constants

API_KEY_ENV_VAR = "GOOGLE_GENERATIVE_AI_API_KEY"

Environment variable for API key.

DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta"

Default base URL for Google Generative AI API.

DEFAULT_PROVIDER_NAME = "google.generative-ai"

Default provider name.

IMAGE_MODEL_IDS = ["imagen-4.0-generate-001", "imagen-4.0-ultra-generate-001", "imagen-4.0-fast-generate-001"]

Known image model IDs for Google Generative AI.

VALID_IMAGE_PROVIDER_OPTIONS = ["personGeneration", "aspectRatio"]

Valid provider options that can be passed to Google Image API.

VALID_LANGUAGE_MODEL_PROVIDER_OPTIONS = ["responseModalities", "thinkingConfig", "cachedContent", "structuredOutputs", "safetySettings", "threshold", "audioTimestamp", "labels", "mediaResolution", "imageConfig", "retrievalConfig"]

Valid provider option keys for filtering.

VERSION = "0.1.0"

Class methods

convert_json_schema_to_openapi_schema(json_schema : JSON::Any | Nil, is_root : Bool = true) : Hash(String, JSON::Any) | Nil

Converts JSON Schema 7 to OpenAPI Schema 3.0.

This is needed because Google Generative AI uses OpenAPI schema format for structured outputs, while the AI SDK uses JSON Schema.

Source
convert_to_google_messages(prompt : Provider::LanguageModel::Prompt, *, is_gemma_model : Bool = false, provider_options_name : String = "google") : ConvertToGoogleMessagesResult

Converts SDK prompt messages to Google Generative AI format.

Source
convert_usage(usage : UsageMetadata | Nil) : Provider::LanguageModel::Usage

Converts Google Generative AI usage metadata to the unified Usage type.

Source
create_google_generative_ai(base_url : String | Nil = nil, api_key : String | Nil = nil, headers : Hash(String, String) | Nil = nil, name : String | Nil = nil) : GoogleGenerativeAIProvider

Creates a Google Generative AI provider instance.

Source
get_model_path(model_id : String) : String

Constructs the model path for API requests.

If the model_id contains a slash (e.g., "projects/my-project/..."), it's returned as-is. Otherwise, "models/" is prepended.

Source
google

Default Google Generative AI provider instance.

Uses the GOOGLE_GENERATIVE_AI_API_KEY environment variable for authentication.

Source
map_finish_reason(finish_reason : String | Nil, *, has_tool_calls : Bool) : FinishReason

Maps Google Generative AI finish reasons to unified finish reasons.

The Google API returns various finish reasons that need to be mapped to the standardized AI SDK finish reasons.

Source
prepare_tools(tools : Array(Tool) | Nil, tool_choice : Provider::LanguageModel::ToolChoice | Nil, model_id : String) : PrepareToolsResult

Prepares tools for the Google Generative AI API.

Source
supported_file_url?(url : URI) : Bool

Checks if a URL is supported for direct file access by Google Generative AI.

Supported URLs:

  • Google Generative Language files API: https://generativelanguage.googleapis.com/v1beta/files/...
  • YouTube URLs (public or unlisted videos): youtube.com/watch?v=... or youtu.be/...
Source

Nested types