### Convert Bidi Setup to Token Setup Source: https://pkg.go.dev/google.golang.org/genai Converts BidiGenerateContentSetup to token setup. This function is part of internal utilities and its signature may change. ```go func ConvertBidiSetupToTokenSetup( body map[string]any, config *CreateAuthTokenConfig, ) map[string]any ``` -------------------------------- ### Implement Files.Get Method Source: https://pkg.go.dev/google.golang.org/genai Retrieves a specific file resource by its name. Requires context, file name, and optional get configuration. ```go func (m Files) Get(ctx context.Context, name string, config *GetFileConfig) (*File, error) ``` -------------------------------- ### Activity Start Marker in Go Source: https://pkg.go.dev/google.golang.org/genai Marks the start of user activity. This can only be sent if automatic (server-side) activity detection is disabled. ```go type ActivityStart struct { } ``` -------------------------------- ### Configure Live Client Session Setup in Go Source: https://pkg.go.dev/google.golang.org/genai Use LiveClientSetup to configure parameters for a streaming generative AI session. This includes specifying the model, generation configuration, system instructions, tools, and various real-time and session management options. ```go type LiveClientSetup struct { // The fully qualified name of the publisher model or tuned model endpoint to // use. Model string `json:"model,omitempty"` // Optional. The generation configuration for the session. // Note: only a subset of fields are supported. GenerationConfig *GenerationConfig `json:"generationConfig,omitempty"` // Optional. The user provided system instructions for the model. // Note: only text should be used in parts and content in each part will be // in a separate paragraph. SystemInstruction *Content `json:"systemInstruction,omitempty"` // Optional. A list of `Tools` the model may use to generate the next response. // A `Tool` is a piece of code that enables the system to interact with // external systems to perform an action, or set of actions, outside of // knowledge and scope of the model. Tools []*Tool `json:"tools,omitempty"` // Optional. Configures the realtime input behavior in BidiGenerateContent. RealtimeInputConfig *RealtimeInputConfig `json:"realtimeInputConfig,omitempty"` // Optional. Configures session resumption mechanism. // If included server will send SessionResumptionUpdate messages. SessionResumption *SessionResumptionConfig `json:"sessionResumption,omitempty"` // Optional. Configures context window compression mechanism. // If included, server will compress context window to fit into given length. ContextWindowCompression *ContextWindowCompressionConfig `json:"contextWindowCompression,omitempty"` // Optional. The transcription of the input aligns with the input audio language. InputAudioTranscription *AudioTranscriptionConfig `json:"inputAudioTranscription,omitempty"` // Optional. The transcription of the output aligns with the language code // specified for the output audio. OutputAudioTranscription *AudioTranscriptionConfig `json:"outputAudioTranscription,omitempty"` // Optional. Configures the proactivity of the model. This allows the model to respond // proactively to // the input and to ignore irrelevant input. Proactivity *ProactivityConfig `json:"proactivity,omitempty"` // Optional. Configures the explicit VAD signal. If enabled, the client will send // vad_signal to indicate the start and end of speech. This allows the server // to process the audio more efficiently. ExplicitVADSignal bool `json:"explicitVadSignal,omitempty"` // Optional. Configures the avatar model behavior. AvatarConfig *AvatarConfig `json:"avatarConfig,omitempty"` // Optional. Safety settings in the request to block unsafe content in the // response. SafetySettings []*SafetySetting `json:"safetySettings,omitempty"` } ``` -------------------------------- ### Live.Connect Source: https://pkg.go.dev/google.golang.org/genai Establishes a WebSocket connection to the specified model with the given configuration. It sends the initial setup message and returns a Session object representing the connection. ```APIDOC ## (*Live) Connect ### Description Connect establishes a WebSocket connection to the specified model with the given configuration. It sends the initial setup message and returns a Session object representing the connection. ### Signature ```go func (r *Live) Connect(context context.Context, model string, config *LiveConnectConfig) (*Session, error) ``` ### Parameters - **context** (context.Context) - The context for the connection. - **model** (string) - The model to connect to. - **config** (*LiveConnectConfig) - The configuration for the connection. ``` -------------------------------- ### Define TuningExample Structure Source: https://pkg.go.dev/google.golang.org/genai Defines a single example for tuning, consisting of required output and optional text input. Not supported in Vertex AI. ```go type TuningExample struct { // Required. The expected model output. Output string `json:"output,omitempty"` // Optional. Text model input. TextInput string `json:"textInput,omitempty"` } ``` -------------------------------- ### LiveServerSetupComplete Source: https://pkg.go.dev/google.golang.org/genai Indicates that the live session setup is complete. This message is sent in response to a `LiveGenerateContentSetup` message from the client. ```APIDOC ## LiveServerSetupComplete ### Description Sent in response to a `LiveGenerateContentSetup` message from the client. ### Fields - **SessionID** (string) - Optional. The session ID of the live session. ``` -------------------------------- ### Get Model Details with Go Source: https://pkg.go.dev/google.golang.org/genai Retrieves a specific model resource by its name. Requires a context and model name. ```go func (m Models) Get(ctx context.Context, model string, config *GetModelConfig) (*Model, error) ``` -------------------------------- ### Create Client Using Environment Variables Source: https://pkg.go.dev/google.golang.org/genai Instantiate a client using default configuration, relying on environment variables for authentication and project details. ```go client, err := genai.NewClient(ctx, &genai.ClientConfig{}) ``` -------------------------------- ### Get Document Function Signature Source: https://pkg.go.dev/google.golang.org/genai Signature for the Get function on Documents. Use this to retrieve a specific document resource by name. ```go func (m Documents) Get(ctx context.Context, name string, config *GetDocumentConfig) (*Document, error) ``` -------------------------------- ### Define DatasetStats Structure Source: https://pkg.go.dev/google.golang.org/genai Provides statistics computed over a tuning dataset, including dropped example details, character counts, example counts, tuning steps, and dataset distributions for user input, messages per example, and user output. This data type is not supported in the Gemini API. ```go type DatasetStats struct { // Output only. A partial sample of the indices (starting from 1) of the dropped examples. DroppedExampleIndices []int64 `json:"droppedExampleIndices,omitempty"` // Output only. For each index in `dropped_example_indices`, the user-facing reason // why the example was dropped. DroppedExampleReasons []string `json:"droppedExampleReasons,omitempty"` // Output only. Number of billable characters in the tuning dataset. TotalBillableCharacterCount int64 `json:"totalBillableCharacterCount,omitempty,string"` // Output only. Number of tuning characters in the tuning dataset. TotalTuningCharacterCount int64 `json:"totalTuningCharacterCount,omitempty,string"` // Output only. Number of examples in the tuning dataset. TuningDatasetExampleCount int64 `json:"tuningDatasetExampleCount,omitempty,string"` // Output only. Number of tuning steps for this Tuning Job. TuningStepCount int64 `json:"tuningStepCount,omitempty,string"` // Output only. Sample user messages in the training dataset uri. UserDatasetExamples []*Content `json:"userDatasetExamples,omitempty"` // Output only. Dataset distributions for the user input tokens. UserInputTokenDistribution *DatasetDistribution `json:"userInputTokenDistribution,omitempty"` // Output only. Dataset distributions for the messages per example. UserMessagePerExampleDistribution *DatasetDistribution `json:"userMessagePerExampleDistribution,omitempty"` // Output only. Dataset distributions for the user output tokens. UserOutputTokenDistribution *DatasetDistribution `json:"userOutputTokenDistribution,omitempty"` } ``` -------------------------------- ### LiveClientSetup Source: https://pkg.go.dev/google.golang.org/genai LiveClientSetup contains configuration that will apply for the duration of the streaming session. ```APIDOC ## LiveClientSetup ### Description LiveClientSetup contains configuration that will apply for the duration of the streaming session. ### Fields - **Model** (string) - The fully qualified name of the publisher model or tuned model endpoint to use. - **GenerationConfig** (*GenerationConfig) - Optional. The generation configuration for the session. Note: only a subset of fields are supported. - **SystemInstruction** (*Content) - Optional. The user provided system instructions for the model. Note: only text should be used in parts and content in each part will be in a separate paragraph. - **Tools** ([]*Tool) - Optional. A list of `Tools` the model may use to generate the next response. A `Tool` is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the model. - **RealtimeInputConfig** (*RealtimeInputConfig) - Optional. Configures the realtime input behavior in BidiGenerateContent. - **SessionResumption** (*SessionResumptionConfig) - Optional. Configures session resumption mechanism. If included server will send SessionResumptionUpdate messages. - **ContextWindowCompression** (*ContextWindowCompressionConfig) - Optional. Configures context window compression mechanism. If included, server will compress context window to fit into given length. - **InputAudioTranscription** (*AudioTranscriptionConfig) - Optional. The transcription of the input aligns with the input audio language. - **OutputAudioTranscription** (*AudioTranscriptionConfig) - Optional. The transcription of the output aligns with the language code specified for the output audio. - **Proactivity** (*ProactivityConfig) - Optional. Configures the proactivity of the model. This allows the model to respond proactively to the input and to ignore irrelevant input. - **ExplicitVADSignal** (bool) - Optional. Configures the explicit VAD signal. If enabled, the client will send vad_signal to indicate the start and end of speech. This allows the server to process the audio more efficiently. - **AvatarConfig** (*AvatarConfig) - Optional. Configures the avatar model behavior. - **SafetySettings** ([]*SafetySetting) - Optional. Safety settings in the request to block unsafe content in the response. ``` -------------------------------- ### Implement Files.Download Method Source: https://pkg.go.dev/google.golang.org/genai Downloads a file from a specified URI. Handles video files by populating their VideoBytes field. Requires context, download URI, and optional download configuration. ```go func (m Files) Download(ctx context.Context, uri DownloadURI, config *DownloadFileConfig) ([]byte, error) ``` -------------------------------- ### Define Start of Speech Sensitivity Constants Source: https://pkg.go.dev/google.golang.org/genai Defines constants for start of speech sensitivity. Use `StartSensitivityHigh` for more frequent detection and `StartSensitivityLow` for less frequent detection. ```go type StartSensitivity string ``` ```go const ( // The default is START_SENSITIVITY_LOW. StartSensitivityUnspecified StartSensitivity = "START_SENSITIVITY_UNSPECIFIED" // Automatic detection will detect the start of speech more often. StartSensitivityHigh StartSensitivity = "START_SENSITIVITY_HIGH" // Automatic detection will detect the start of speech less often. StartSensitivityLow StartSensitivity = "START_SENSITIVITY_LOW" ) ``` -------------------------------- ### Define Interval Struct Source: https://pkg.go.dev/google.golang.org/genai Represents a time interval with inclusive start and exclusive end times. An empty interval occurs when start equals end. An interval matches any time if both are unspecified. ```go type Interval struct { // Optional. Exclusive end of the interval. If specified, a Timestamp matching this // interval will have to be before the end. EndTime time.Time `json:"endTime,omitempty"` // Optional. Inclusive start of the interval. If specified, a Timestamp matching this // interval will have to be the same or after the start. StartTime time.Time `json:"startTime,omitempty"` } ``` -------------------------------- ### Caches.Get Source: https://pkg.go.dev/google.golang.org/genai Gets a cached content resource. ```APIDOC ## Caches.Get ### Description Get gets a cached content resource. ### Method func (Caches) Get(ctx context.Context, name string, config *GetCachedContentConfig) (*CachedContent, error) ### Parameters * `ctx` (context.Context) - The context for the request. * `name` (string) - The name of the cached content resource to retrieve. * `config` (*GetCachedContentConfig) - Configuration for getting the cached content. ### Response * `*CachedContent` - The retrieved cached content resource. * `error` - An error if the retrieval failed. ``` -------------------------------- ### Create Content from Executable Code Source: https://pkg.go.dev/google.golang.org/genai Constructs a Content object from source code, language, and role. Defaults to RoleUser if role is empty. ```go func NewContentFromExecutableCode(code string, language Language, role Role) *Content ``` -------------------------------- ### Get Source: https://pkg.go.dev/google.golang.org/genai Retrieves a specific model resource by its name. ```APIDOC ## Get ### Description Retrieves a specific model resource by its name. ### Method Signature ```go func (m Models) Get(ctx context.Context, model string, config *GetModelConfig) (*Model, error) ``` ``` -------------------------------- ### Live Struct Go Source: https://pkg.go.dev/google.golang.org/genai Entry point for establishing real-time WebSocket connections. Managed when creating a client via NewClient, accessed via the `Live` field of a `Client` instance. ```go type Live struct { // contains filtered or unexported fields } ``` -------------------------------- ### Implement Files.List Method Source: https://pkg.go.dev/google.golang.org/genai Retrieves a paginated list of file resources. Requires context and list configuration. Returns a Page object containing file data and pagination information. ```go func (m Files) List(ctx context.Context, config *ListFilesConfig) (Page[File], error) ``` -------------------------------- ### Get Tuning Job Source: https://pkg.go.dev/google.golang.org/genai Retrieves a tuning job resource. ```APIDOC ## Get Tuning Job ### Description Retrieves a tuning job resource. ### Method `Get` ### Parameters - `ctx` (context.Context) - The context for the request. - `name` (string) - The name of the tuning job to retrieve. - `config` (*GetTuningJobConfig) - Configuration for retrieving the tuning job. ### Returns - `*TuningJob` - The requested tuning job resource. - `error` - An error if the retrieval fails. ``` -------------------------------- ### Get FileSearchStore Source: https://pkg.go.dev/google.golang.org/genai Retrieves a specific FileSearchStore by its name and configuration. ```go func (m FileSearchStores) Get(ctx context.Context, name string, config *GetFileSearchStoreConfig) (*FileSearchStore, error) ``` -------------------------------- ### Implement Files.All Method Source: https://pkg.go.dev/google.golang.org/genai Retrieves all file resources using an iterator. This method handles pagination internally, simplifying the process of fetching all entries without manual token management. ```go func (m Files) All(ctx context.Context) iter.Seq2[*File, error] ``` -------------------------------- ### VADSignalType Source: https://pkg.go.dev/google.golang.org/genai The type of the VAD signal, indicating the start or end of a sentence. ```APIDOC ## VADSignalType ### Description The type of the VAD signal. ### Constants - **VADSignalTypeUnspecified** (VADSignalType) - The default is VAD_SIGNAL_TYPE_UNSPECIFIED. - **VADSignalTypeSos** (VADSignalType) - Start of sentence signal. - **VADSignalTypeEos** (VADSignalType) - End of sentence signal. ``` -------------------------------- ### NewDownloadURIFromVideo Source: https://pkg.go.dev/google.golang.org/genai Creates a DownloadURI from a Video. This function is available starting from v1.0.0. ```APIDOC ## NewDownloadURIFromVideo ### Description Creates a DownloadURI from a Video. ### Method Signature ```go func NewDownloadURIFromVideo(v *Video) DownloadURI ``` ### Parameters - **v** (*Video) - The Video to create the DownloadURI from. ### Returns - **DownloadURI** - A DownloadURI representing the video. ``` -------------------------------- ### ClientConfig Method Signature Source: https://pkg.go.dev/google.golang.org/genai Returns a copy of the ClientConfig used to create the client. ```go func (c Client) ClientConfig() ClientConfig ``` -------------------------------- ### NewDownloadURIFromGeneratedVideo Source: https://pkg.go.dev/google.golang.org/genai Creates a DownloadURI from a GeneratedVideo. This function is available starting from v1.0.0. ```APIDOC ## NewDownloadURIFromGeneratedVideo ### Description Creates a DownloadURI from a GeneratedVideo. ### Method Signature ```go func NewDownloadURIFromGeneratedVideo(v *GeneratedVideo) DownloadURI ``` ### Parameters - **v** (*GeneratedVideo) - The GeneratedVideo to create the DownloadURI from. ### Returns - **DownloadURI** - A DownloadURI representing the generated video. ``` -------------------------------- ### List Models with Go Source: https://pkg.go.dev/google.golang.org/genai Retrieves a paginated list of model resources. Use the provided configuration for listing. ```go func (m Models) List(ctx context.Context, config *ListModelsConfig) (Page[Model], error) ``` -------------------------------- ### NewDownloadURIFromFile Source: https://pkg.go.dev/google.golang.org/genai Creates a DownloadURI from a File. This function is available starting from v1.0.0. ```APIDOC ## NewDownloadURIFromFile ### Description Creates a DownloadURI from a File. ### Method Signature ```go func NewDownloadURIFromFile(f *File) DownloadURI ``` ### Parameters - **f** (*File) - The File to create the DownloadURI from. ### Returns - **DownloadURI** - A DownloadURI representing the file. ``` -------------------------------- ### Create Content from Parts Source: https://pkg.go.dev/google.golang.org/genai Builds a Content object from a list of parts and a role. Defaults to RoleUser if role is empty. ```go func NewContentFromParts(parts []*Part, role Role) *Content ``` -------------------------------- ### Documents.Delete Source: https://pkg.go.dev/google.golang.org/genai Deletes a document resource. This method is available starting from v1.34.0. ```APIDOC ## Documents.Delete ### Description Deletes a document resource. ### Method Signature ```go func (m Documents) Delete(ctx context.Context, name string, config *DeleteDocumentConfig) error ``` ### Parameters - **ctx** (context.Context) - The context for the request. - **name** (string) - The name of the document to delete. - **config** (*DeleteDocumentConfig) - Configuration options for the delete operation. ``` -------------------------------- ### NewDownloadURIFromVideo Constructor Source: https://pkg.go.dev/google.golang.org/genai Creates a DownloadURI from a Video object. ```go func NewDownloadURIFromVideo(v *Video) DownloadURI ``` -------------------------------- ### Session.Receive Source: https://pkg.go.dev/google.golang.org/genai Receives a message from the server. Use this to get responses or updates from the session. ```APIDOC ## Receive ### Description Receives a message from the server. ### Method func (s *Session) Receive() (*LiveServerMessage, error) ### Response #### Success Response (200) - **LiveServerMessage** (*LiveServerMessage) - The message received from the server. - **error** (error) - An error if a message could not be received. ``` -------------------------------- ### Documents.Get Source: https://pkg.go.dev/google.golang.org/genai Retrieves a specific document resource. This method is available starting from v1.34.0. ```APIDOC ## Documents.Get ### Description Retrieves a specific document resource. ### Method Signature ```go func (m Documents) Get(ctx context.Context, name string, config *GetDocumentConfig) (*Document, error) ``` ### Parameters - **ctx** (context.Context) - The context for the request. - **name** (string) - The name of the document to retrieve. - **config** (*GetDocumentConfig) - Configuration options for the get operation. ### Returns - **(*Document, error)** - A pointer to the Document resource and an error if the operation fails. ``` -------------------------------- ### Create FileSearchStore Source: https://pkg.go.dev/google.golang.org/genai Creates a new FileSearchStore with the provided configuration. ```go func (m FileSearchStores) Create(ctx context.Context, config *CreateFileSearchStoreConfig) (*FileSearchStore, error) ``` -------------------------------- ### Connect to Live Session Go Source: https://pkg.go.dev/google.golang.org/genai Establishes a WebSocket connection to a specified model with given configuration. Returns a Session object representing the connection. ```go client, _ := genai.NewClient(ctx, &genai.ClientConfig{}) session, _ := client.Live.Connect(ctx, model, &genai.LiveConnectConfig{}). ``` -------------------------------- ### Caches.Get Source: https://pkg.go.dev/google.golang.org/genai Retrieves cached content. Requires context, a name for the cache, and get configuration. ```APIDOC ## Caches.Get ### Description Retrieves cached content using its name and specified configuration. ### Method func (m Caches) Get(ctx context.Context, name string, config *GetCachedContentConfig) (*CachedContent, error) ### Parameters #### Path Parameters - **name** (string) - Required - The name of the cache to retrieve. #### Request Body - **config** (*GetCachedContentConfig) - Required - Configuration for retrieving cached content. ### Response #### Success Response (200) - **CachedContent** (*CachedContent) - The retrieved cached content. - **error** (error) - An error if retrieval fails. ``` -------------------------------- ### Documents.List Source: https://pkg.go.dev/google.golang.org/genai Retrieves a paginated list of document resources. This method is available starting from v1.34.0. ```APIDOC ## Documents.List ### Description Retrieves a paginated list of documents resources. ### Method Signature ```go func (m Documents) List(ctx context.Context, parent string, config *ListDocumentsConfig) (Page[Document], error) ``` ### Parameters - **ctx** (context.Context) - The context for the request. - **parent** (string) - The parent resource name. - **config** (*ListDocumentsConfig) - Configuration options for the list operation. ### Returns - **(Page[Document], error)** - A Page object containing Document resources and an error if the operation fails. ``` -------------------------------- ### Create Gemini API Client Source: https://pkg.go.dev/google.golang.org/genai Instantiate a client for the Gemini Developer API. Requires an API key and specifies the Gemini API backend. ```go client, err := genai.NewClient(ctx, &genai.ClientConfig{ APIKey: apiKey, Backend: genai.BackendGeminiAPI, }) ``` -------------------------------- ### Create Content from Text Source: https://pkg.go.dev/google.golang.org/genai Constructs a Content object from a text string and role. Defaults to RoleUser if role is empty. ```go func NewContentFromText(text string, role Role) *Content ``` -------------------------------- ### Get Executable Code from GenerateContentResponse Source: https://pkg.go.dev/google.golang.org/genai Retrieves the executable code from a GenerateContentResponse. This method is available from v0.5.0. ```go func (r *GenerateContentResponse) ExecutableCode() string ``` -------------------------------- ### Define VADSignalType in Go Source: https://pkg.go.dev/google.golang.org/genai The type of the VAD signal, used to indicate start or end of speech. ```go type VADSignalType string const ( // The default is VAD_SIGNAL_TYPE_UNSPECIFIED. VADSignalTypeUnspecified VADSignalType = "VAD_SIGNAL_TYPE_UNSPECIFIED" // Start of sentence signal. VADSignalTypeSos VADSignalType = "VAD_SIGNAL_TYPE_SOS" // End of sentence signal. VADSignalTypeEos VADSignalType = "VAD_SIGNAL_TYPE_EOS" ) ``` -------------------------------- ### Implement Files.UploadFromPath Method Source: https://pkg.go.dev/google.golang.org/genai Uploads a file from a specified local path to the associated file storage. Returns information about the created file. Requires context, the file path, and upload configuration. ```go func (m Files) UploadFromPath(ctx context.Context, path string, config *UploadFileConfig) (*File, error) ``` -------------------------------- ### NewDownloadURIFromGeneratedVideo Constructor Source: https://pkg.go.dev/google.golang.org/genai Creates a DownloadURI from a GeneratedVideo object. ```go func NewDownloadURIFromGeneratedVideo(v *GeneratedVideo) DownloadURI ``` -------------------------------- ### RAGChunkPageSpan Source: https://pkg.go.dev/google.golang.org/genai Represents where the chunk starts and ends in the document. This data type is not supported in Gemini API. ```APIDOC ## RAGChunkPageSpan Represents where the chunk starts and ends in the document. This data type is not supported in Gemini API. ### Fields - **FirstPage** (int32) - Page where chunk starts in the document. Inclusive. 1-indexed. - **LastPage** (int32) - Page where chunk ends in the document. Inclusive. 1-indexed. ``` -------------------------------- ### Create Part from URI Source: https://pkg.go.dev/google.golang.org/genai Builds a Part from a given file URI and mime type. ```go func NewPartFromURI(fileURI, mimeType string) *Part ``` -------------------------------- ### Create Content from URI Source: https://pkg.go.dev/google.golang.org/genai Builds a Content object from a file URI, MIME type, and role. Defaults to RoleUser if role is empty. ```go func NewContentFromURI(fileURI, mimeType string, role Role) *Content ``` -------------------------------- ### Get Function Calls from GenerateContentResponse Source: https://pkg.go.dev/google.golang.org/genai Retrieves a list of function calls from a GenerateContentResponse. This method is available from v0.1.0. ```go func (r *GenerateContentResponse) FunctionCalls() []*FunctionCall ``` -------------------------------- ### Connect (Live Client) Source: https://pkg.go.dev/google.golang.org/genai Establishes a live connection to a model. This allows for real-time interactions and streaming responses. ```APIDOC ## Connect (Live Client) ### Description Establishes a live connection to a model. This allows for real-time interactions and streaming responses. ### Function Signature func (r *Live) Connect(context context.Context, model string, config *LiveConnectConfig) (*Session, error) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **context** (context.Context) - The context for the connection request. - **model** (string) - The identifier of the model to connect to. - **config** (*LiveConnectConfig) - Configuration options for the live connection. ### Request Example ```go // Example usage (assuming appropriate imports and LiveConnectConfig setup) // liveClient := &Live{} // session, err := liveClient.Connect(context.Background(), "model-id", &LiveConnectConfig{...}) // if err != nil { // log.Fatalf("Failed to connect: %v", err) // } ``` ### Response #### Success Response (200) - **Session** (*Session) - A pointer to the established session object. - **error** (error) - An error if the connection fails. #### Response Example ```json { "sessionId": "session-123", "status": "connected" } ``` ``` -------------------------------- ### Create Gemini Enterprise Agent Platform Client Source: https://pkg.go.dev/google.golang.org/genai Instantiate a client for the Gemini Enterprise Agent Platform. Requires project ID and location, and specifies the Enterprise backend. ```go client, err := genai.NewClient(ctx, &genai.ClientConfig{ Project: project, Location: location, Backend: genai.BackendEnterprise, }) ``` -------------------------------- ### Get Code Execution Result from GenerateContentResponse Source: https://pkg.go.dev/google.golang.org/genai Retrieves the code execution result from a GenerateContentResponse. This method is available from v0.5.0. ```go func (r *GenerateContentResponse) CodeExecutionResult() string ``` -------------------------------- ### Define CreateTuningJobConfig in Go Source: https://pkg.go.dev/google.golang.org/genai Defines the configuration options for creating a fine-tuning job, including dataset, model display name, training parameters, and output settings. Use this struct to specify all parameters for a tuning job request. ```go type CreateTuningJobConfig struct { // Optional. Used to override HTTP request options. HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` // The method to use for tuning (SUPERVISED_FINE_TUNING or PREFERENCE_TUNING or DISTILLATION). // If not set, the default method (SFT) will be used. Method TuningMethod `json:"method,omitempty"` // Optional. Validation dataset for tuning. The dataset must be formatted as a JSONL // file. ValidationDataset *TuningValidationDataset `json:"validationDataset,omitempty"` // Optional. The display name of the tuned Model. The name can be up to 128 characters // long and can consist of any UTF-8 characters. TunedModelDisplayName string `json:"tunedModelDisplayName,omitempty"` // Optional. The description of the TuningJob Description string `json:"description,omitempty"` // Optional. Number of complete passes the model makes over the entire training dataset // during training. EpochCount *int32 `json:"epochCount,omitempty"` // Optional. Multiplier for adjusting the default learning rate. 1P models only. Mutually // exclusive with learning_rate. LearningRateMultiplier *float32 `json:"learningRateMultiplier,omitempty"` // Optional. If set to true, disable intermediate checkpoints and only the last checkpoint // will be exported. Otherwise, enable intermediate checkpoints. ExportLastCheckpointOnly *bool `json:"exportLastCheckpointOnly,omitempty"` // Optional. The optional checkpoint ID of the pre-tuned model to use for tuning, if // applicable. PreTunedModelCheckpointID string `json:"preTunedModelCheckpointId,omitempty"` // Optional. Adapter size for tuning. AdapterSize AdapterSize `json:"adapterSize,omitempty"` // Optional. Tuning mode for tuning. TuningMode TuningMode `json:"tuningMode,omitempty"` // Optional. Custom base model for tuning. This is only supported for OSS models in // Gemini Enterprise Agent Platform. CustomBaseModel string `json:"customBaseModel,omitempty"` // Optional. The batch size hyperparameter for tuning. This is only supported for OSS // models in Gemini Enterprise Agent Platform. BatchSize *int32 `json:"batchSize,omitempty"` // Optional. The learning rate for tuning. OSS models only. Mutually exclusive with // learning_rate_multiplier. LearningRate *float32 `json:"learningRate,omitempty"` // Optional. The labels with user-defined metadata to organize TuningJob and generated // resources such as Model and Endpoint. Label keys and values can be no longer than // 64 characters (Unicode codepoints), can only contain lowercase letters, numeric characters, // underscores and dashes. International characters are allowed. See https://goo.gl/xmQnxf // for more information and examples of labels. Labels map[string]string `json:"labels,omitempty"` // Optional. Weight for KL Divergence regularization, Preference Optimization tuning // only. Beta *float32 `json:"beta,omitempty"` // Optional. The base teacher model that is being distilled. Distillation only. BaseTeacherModel string `json:"baseTeacherModel,omitempty"` // Optional. The resource name of the Tuned teacher model. Distillation only. TunedTeacherModelSource string `json:"tunedTeacherModelSource,omitempty"` // Optional. Multiplier for adjusting the weight of the SFT loss. Distillation only. SftLossWeightMultiplier *float32 `json:"sftLossWeightMultiplier,omitempty"` // Optional. The Google Cloud Storage location where the tuning job outputs are written. OutputURI string `json:"outputUri,omitempty"` // Optional. The encryption spec of the tuning job. Customer-managed encryption key // options for a TuningJob. If this is set, then all resources created by the TuningJob // will be encrypted with provided encryption key. EncryptionSpec *EncryptionSpec `json:"encryptionSpec,omitempty"` } ``` -------------------------------- ### Get Text Content from GenerateContentResponse Source: https://pkg.go.dev/google.golang.org/genai Concatenates all text parts within a GenerateContentResponse into a single string. This method is available from v0.1.0. ```go func (r *GenerateContentResponse) Text() string ``` -------------------------------- ### NewDownloadURIFromFile Constructor Source: https://pkg.go.dev/google.golang.org/genai Creates a DownloadURI from a File object. ```go func NewDownloadURIFromFile(f *File) DownloadURI ``` -------------------------------- ### Get Batch Job Resource Source: https://pkg.go.dev/google.golang.org/genai Retrieves a specific batch job resource using its context and name. Configuration options can be provided. ```go func (m Batches) Get(ctx context.Context, name string, config *GetBatchJobConfig) (*BatchJob, error) ``` -------------------------------- ### Create Tuning Job (Go) Source: https://pkg.go.dev/google.golang.org/genai Creates a tuning job resource. This function requires a context, the base model to use, the training dataset, and configuration for creating the job. ```go func (t Tunings) Tune(ctx context.Context, baseModel string, trainingDataset *TuningDataset, config *CreateTuningJobConfig) (*TuningJob, error) ``` -------------------------------- ### GenerateContent with Code Execution (Gemini API) Source: https://pkg.go.dev/google.golang.org/genai Demonstrates calling GenerateContent with code execution for the Gemini API. Ensure necessary imports and authentication are configured. ```go func (m Models) GenerateContent(ctx context.Context, model string, contents []*Content, config *GenerateContentConfig) (*GenerateContentResponse, error) ``` -------------------------------- ### Video Metadata Structure Source: https://pkg.go.dev/google.golang.org/genai Defines the structure for video metadata, including optional start and end offsets for clipping and frame rate. ```go type VideoMetadata struct { // Optional. The end offset of the video. EndOffset time.Duration `json:"endOffset,omitempty"` // Optional. The frame rate of the video sent to the model. If not specified, the default // value is 1.0. The valid range is (0.0, 24.0]. FPS *float64 `json:"fps,omitempty"` // Optional. The start offset of the video. StartOffset time.Duration `json:"startOffset,omitempty"` } ``` -------------------------------- ### Implement Caches.Create Method in Go Source: https://pkg.go.dev/google.golang.org/genai Creates a new cached content resource. Requires a context, model name, and configuration for creating the cached content. ```go func (m Caches) Create(ctx context.Context, model string, config *CreateCachedContentConfig) (*CachedContent, error) ``` -------------------------------- ### Activity Handling Constants in Go Source: https://pkg.go.dev/google.golang.org/genai Defines constants for activity handling behaviors, including unspecified, start of activity interrupts, and no interruption. ```go const ( // If unspecified, the default behavior is `START_OF_ACTIVITY_INTERRUPTS`. ActivityHandlingUnspecified ActivityHandling = "ACTIVITY_HANDLING_UNSPECIFIED" // If true, start of activity will interrupt the model's response (also called "barge // in"). The model's current response will be cut-off in the moment of the interruption. // This is the default behavior. ActivityHandlingStartOfActivityInterrupts ActivityHandling = "START_OF_ACTIVITY_INTERRUPTS" // The model's response will not be interrupted. ActivityHandlingNoInterruption ActivityHandling = "NO_INTERRUPTION" ) ``` -------------------------------- ### Define PrebuiltVoiceConfig Structure Source: https://pkg.go.dev/google.golang.org/genai Configuration for a prebuilt voice, specifying the name of the voice to use. ```go type PrebuiltVoiceConfig struct { // The name of the prebuilt voice to use. VoiceName string `json:"voiceName,omitempty"` } ``` -------------------------------- ### Define LiveServerSetupComplete Go Type Source: https://pkg.go.dev/google.golang.org/genai Represents the completion of the live content setup process. This is sent in response to a client's `LiveGenerateContentSetup` message. ```go type LiveServerSetupComplete struct { // Optional. The session ID of the live session. SessionID string `json:"sessionId,omitempty"` } ``` -------------------------------- ### Define CreateFileConfig in Go Source: https://pkg.go.dev/google.golang.org/genai Defines the configuration for creating a file, allowing overrides for HTTP request options and the option to return the raw HTTP response. ```go type CreateFileConfig struct { // Optional. Used to override HTTP request options. HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` // Optional. If true, the raw HTTP response will be returned in the 'sdk_http_response' // field. ShouldReturnHTTPResponse bool `json:"shouldReturnHttpResponse,omitempty"` } ``` -------------------------------- ### Define Voice Activity Types Source: https://pkg.go.dev/google.golang.org/genai Defines an enum for the type of voice activity signals, including unspecified, activity start, and activity end. ```go type VoiceActivityType string const ( // The default is VOICE_ACTIVITY_TYPE_UNSPECIFIED. VoiceActivityTypeUnspecified VoiceActivityType = "TYPE_UNSPECIFIED" // Start of sentence signal. VoiceActivityTypeActivityStart VoiceActivityType = "ACTIVITY_START" // End of sentence signal. VoiceActivityTypeActivityEnd VoiceActivityType = "ACTIVITY_END" ) ``` -------------------------------- ### Interval Type Source: https://pkg.go.dev/google.golang.org/genai Represents a time interval with inclusive start and exclusive end times. Useful for defining time ranges for operations or data. ```APIDOC ## type Interval ```go type Interval struct { // Optional. Exclusive end of the interval. If specified, a Timestamp matching this // interval will have to be before the end. EndTime time.Time `json:"endTime,omitempty"` // Optional. Inclusive start of the interval. If specified, a Timestamp matching this // interval will have to be the same or after the start. StartTime time.Time `json:"startTime,omitempty"` } ``` Represents a time interval, encoded as a Timestamp start (inclusive) and a Timestamp end (exclusive). The start must be less than or equal to the end. When the start equals the end, the interval is empty (matches no time). When both start and end are unspecified, the interval matches any time. ``` -------------------------------- ### Configure Batch Job Listing Source: https://pkg.go.dev/google.golang.org/genai Configuration for listing batch jobs, allowing overrides for HTTP request options and pagination settings. ```go type ListBatchJobsConfig struct { // Optional. Used to override HTTP request options. HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` // Optional. PageSize specifies the maximum number of cached contents to return per // API call. If zero, the server will use a default value. PageSize int32 `json:"pageSize,omitempty"` // Optional. PageToken represents a token used for pagination in API responses. It's // an opaque string that should be passed to subsequent requests to retrieve the next // page of results. An empty PageToken typically indicates that there are no further // pages available. PageToken string `json:"pageToken,omitempty"` // Optional. Filter string `json:"filter,omitempty"` } ``` -------------------------------- ### List Tuning Jobs (Go) Source: https://pkg.go.dev/google.golang.org/genai Retrieves a paginated list of tuning_jobs resources. Requires a context and configuration for listing jobs. ```go func (m Tunings) List(ctx context.Context, config *ListTuningJobsConfig) (Page[TuningJob], error) ``` -------------------------------- ### Create New Chat Session Source: https://pkg.go.dev/google.golang.org/genai Initializes a new chat session with the specified model, configuration, and optional history. Access this via `client.Chats.Create`. ```go func (c *Chats) Create(ctx context.Context, model string, config *GenerateContentConfig, history []*Content) (*Chat, error) ``` -------------------------------- ### Define Speaker Voice Configuration Source: https://pkg.go.dev/google.golang.org/genai Defines the configuration for a single speaker in a multi-speaker setup. Requires the speaker's name and their associated voice configuration. ```go type SpeakerVoiceConfig struct { // Required. The name of the speaker. This should be the same as the speaker name used // in the prompt. Speaker string `json:"speaker,omitempty"` // Required. The configuration for the voice of this speaker. VoiceConfig *VoiceConfig `json:"voiceConfig,omitempty"` } ``` -------------------------------- ### Configure File Search Store Listing Source: https://pkg.go.dev/google.golang.org/genai Configuration for listing file search stores, supporting HTTP option overrides and pagination parameters. ```go type ListFileSearchStoresConfig struct { // Optional. Used to override HTTP request options. HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` // Optional. PageSize specifies the maximum number of cached contents to return per // API call. If zero, the server will use a default value. PageSize int32 `json:"pageSize,omitempty"` // Optional. PageToken represents a token used for pagination in API responses. It's // an opaque string that should be passed to subsequent requests to retrieve the next // page of results. An empty PageToken typically indicates that there are no further // pages available. PageToken string `json:"pageToken,omitempty"` } ``` -------------------------------- ### Create New Style Reference Image Source: https://pkg.go.dev/google.golang.org/genai Constructor function for creating a new `StyleReferenceImage`. Requires a reference image, its ID, and style configuration. ```go func NewStyleReferenceImage(referenceImage *Image, referenceID int32, config *StyleReferenceConfig) *StyleReferenceImage ``` -------------------------------- ### Define AudioTranscriptionConfig Struct in Go Source: https://pkg.go.dev/google.golang.org/genai Defines the AudioTranscriptionConfig struct for configuring audio transcription, including optional language codes. This configuration is used in Setup. ```go type AudioTranscriptionConfig struct { // Optional. The language codes of the audio. BCP-47 language code. If not set, the // transcription will be in the language detected by the model. If set, the server will // use the language code specified in the model config as a hint for the language of // the audio LanguageCodes []string `json:"languageCodes,omitempty"` } ``` -------------------------------- ### Configure Document Listing Source: https://pkg.go.dev/google.golang.org/genai Configuration for listing documents, allowing HTTP option overrides and pagination controls such as PageSize and PageToken. ```go type ListDocumentsConfig struct { // Optional. Used to override HTTP request options. HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` // Optional. PageSize specifies the maximum number of cached contents to return per // API call. If zero, the server will use a default value. PageSize int32 `json:"pageSize,omitempty"` // Optional. PageToken represents a token used for pagination in API responses. It's // an opaque string that should be passed to subsequent requests to retrieve the next // page of results. An empty PageToken typically indicates that there are no further // pages available. PageToken string `json:"pageToken,omitempty"` } ``` -------------------------------- ### Get Tuning Job Details (Go) Source: https://pkg.go.dev/google.golang.org/genai Retrieves a specific tuning job resource by its name. Requires a context, the job name, and configuration for the retrieval. ```go func (t Tunings) Get(ctx context.Context, name string, config *GetTuningJobConfig) (*TuningJob, error) ``` -------------------------------- ### Retrieve Chat History Source: https://pkg.go.dev/google.golang.org/genai Fetches the conversation history for a chat session. Specify `curated = true` to get the curated history, or `false` for the comprehensive history. ```go func (c *Chat) History(curated bool) []*Content ``` -------------------------------- ### Define CreateFileSearchStoreConfig in Go Source: https://pkg.go.dev/google.golang.org/genai Defines optional parameters for creating a file search store, including HTTP options, display name, and embedding model. ```go type CreateFileSearchStoreConfig struct { // Optional. Used to override HTTP request options. HTTPOptions *HTTPOptions `json:"httpOptions,omitempty"` // Optional. The human-readable display name for the file search store. DisplayName string `json:"displayName,omitempty"` // Optional. The embedding model to use for the FileSearchStore. // Format: `models/{model}`. If not specified, the default embedding model will be used. EmbeddingModel string `json:"embeddingModel,omitempty"` } ``` -------------------------------- ### Implement Files.Delete Method Source: https://pkg.go.dev/google.golang.org/genai Deletes a file resource identified by its name. Requires a context, the file name, and optional delete configuration. ```go func (m Files) Delete(ctx context.Context, name string, config *DeleteFileConfig) (*DeleteFileResponse, error) ``` -------------------------------- ### Get Videos Operation Signature Source: https://pkg.go.dev/google.golang.org/genai Signature for retrieving the status and result of a long-running video generation operation. Use this to check if an operation is done, successful, or failed. ```go func (m Operations) GetVideosOperation(ctx context.Context, operation *GenerateVideosOperation, config *GetOperationConfig) (*GenerateVideosOperation, error) ``` -------------------------------- ### Define Search Entry Point for Grounding Sources Source: https://pkg.go.dev/google.golang.org/genai The SearchEntryPoint struct serves as the entry point for searching grounding sources. It includes fields for rendered web content and an SDK blob. ```go type SearchEntryPoint struct { // Optional. Web content snippet that can be embedded in a web page // or an app webview. RenderedContent string `json:"renderedContent,omitempty"` // Optional. JSON representing array of tuples. SDKBlob []byte `json:"sdkBlob,omitempty"` } ``` -------------------------------- ### AutomaticActivityDetection Source: https://pkg.go.dev/google.golang.org/genai Configures automatic detection of activity. This includes settings for voice and text input, speech sensitivity, and padding durations for start and end of speech detection. ```APIDOC ## type AutomaticActivityDetection ### Description Configures automatic detection of activity. Optional fields allow enabling/disabling voice and text input as activity signals, setting speech sensitivity, and defining padding durations for start and end of speech detection. ### Fields - **Disabled** (bool) - Optional. If enabled, detected voice and text input count as activity. If disabled, the client must send activity signals. - **StartOfSpeechSensitivity** (StartSensitivity) - Optional. Determines how likely speech is to be detected. - **EndOfSpeechSensitivity** (EndSensitivity) - Optional. Determines how likely detected speech is ended. - **PrefixPaddingMs** (*int32) - Optional. The required duration of detected speech before start-of-speech is committed. Lower values increase sensitivity but also false positives. Higher values increase latency. - **SilenceDurationMs** (*int32) - Optional. The required duration of detected non-speech (e.g. silence) before end-of-speech is committed. Larger values allow longer speech gaps but increase latency. ``` -------------------------------- ### Define TuningDataset Structure Source: https://pkg.go.dev/google.golang.org/genai Defines the structure for a supervised fine-tuning training dataset, specifying GCS URI, Vertex AI dataset resource, or inline examples. ```go type TuningDataset struct { // Optional. GCS URI of the file containing training dataset in JSONL format. GCSURI string `json:"gcsUri,omitempty"` // Optional. The resource name of the Gemini Enterprise Agent Platform (previously known // as Vertex AI) Multimodal Dataset that is used as training dataset. Example: 'projects/my-project-id-or-number/locations/my-location/datasets/my-dataset-id'. VertexDatasetResource string `json:"vertexDatasetResource,omitempty"` // Optional. Inline examples with simple input/output text. Examples []*TuningExample `json:"examples,omitempty"` } ``` -------------------------------- ### Client.NewClient Source: https://pkg.go.dev/google.golang.org/genai Creates a new client instance for interacting with the GenAI API. Requires context and client configuration. ```APIDOC ## Client.NewClient ### Description Initializes and returns a new `Client` instance for interacting with the Google GenAI API. This function requires an active `context.Context` and a `ClientConfig`. ### Method func NewClient(ctx context.Context, cc *ClientConfig) (*Client, error) ### Parameters #### Request Body - **ctx** (context.Context) - Required - The context for the request. - **cc** (*ClientConfig) - Required - Configuration settings for the client. ``` -------------------------------- ### Define GeminiPreferenceExample Structure Source: https://pkg.go.dev/google.golang.org/genai Represents an input example for preference optimization, including prompt contents and a list of completions. This data type is not supported in the Gemini API. ```go type GeminiPreferenceExample struct { // List of completions for a given prompt. Completions []*GeminiPreferenceExampleCompletion `json:"completions,omitempty"` // Multi-turn contents that represents the Prompt. Contents []*Content `json:"contents,omitempty"` } ``` -------------------------------- ### Define ComputerUse Structure Source: https://pkg.go.dev/google.golang.org/genai Defines the configuration for supporting computer use, including environment and excluded functions. ```go type ComputerUse struct { // Optional. Required. The environment being operated. Environment Environment `json:"environment,omitempty"` // Optional. By default, predefined functions are included in the final model call. // Some of them can be explicitly excluded from being automatically included. // This can serve two purposes: // 1. Using a more restricted / different action space. // 2. Improving the definitions / instructions of predefined functions. ExcludedPredefinedFunctions []string `json:"excludedPredefinedFunctions,omitempty"` } ```