├── .release-please-manifest.json ├── .github ├── release-trigger.yml ├── release-please.yml └── workflows │ ├── publish-javadoc.yml │ ├── unit-tests.yml │ └── stale.yml ├── CONTRIBUTING.md ├── examples ├── resources │ ├── logo.jpg │ ├── shapes.jpg │ ├── umbrella.jpg │ ├── watercolor_night_sky.jpg │ └── test.txt ├── src │ └── main │ │ └── java │ │ └── com │ │ └── google │ │ └── genai │ │ └── examples │ │ ├── LocalCountTokens.java │ │ ├── LocalComputeTokens.java │ │ ├── EmbedContent.java │ │ ├── CountTokens.java │ │ ├── GenerateContentWithHttpOptions.java │ │ ├── ComputeTokens.java │ │ ├── GenerateContentWithClientOptions.java │ │ ├── Constants.java │ │ └── EmbedContentAsync.java └── pom.xml ├── src ├── test │ ├── resources │ │ ├── logo.jpg │ │ ├── bridge1.png │ │ ├── google.png │ │ ├── shapes.jpg │ │ ├── umbrella.jpg │ │ ├── checkerboard.png │ │ └── watercolor_night_sky.jpg │ └── java │ │ └── com │ │ └── google │ │ └── genai │ │ ├── FakeApiResponse.java │ │ ├── types │ │ ├── FunctionResponsePartTest.java │ │ └── VideoMetadataTest.java │ │ ├── TestUtils.java │ │ ├── ReplayBase64Sanitizer.java │ │ ├── errors │ │ └── GenAiIOExceptionTest.java │ │ ├── NativeImageReflectionTest.java │ │ ├── AsyncTokensTest.java │ │ ├── OperationsTest.java │ │ └── EnvironmentVariablesMockingExtension.java └── main │ ├── resources │ └── META-INF │ │ └── native-image │ │ └── com.google.genai │ │ └── google-genai │ │ ├── predefined-classes-config.json │ │ ├── serialization-config.json │ │ ├── jni-config.json │ │ └── resource-config.json │ └── java │ └── com │ └── google │ └── genai │ ├── errors │ ├── ClientException.java │ ├── ServerException.java │ ├── ExcludeFromGeneratedCoverageReport.java │ ├── GenAiIOException.java │ └── BaseException.java │ ├── types │ ├── ReferenceImage.java │ ├── ExcludeFromGeneratedCoverageReport.java │ ├── UrlContext.java │ ├── ActivityEnd.java │ ├── ActivityStart.java │ ├── AudioTranscriptionConfig.java │ ├── ToolCodeExecution.java │ ├── ExternalApiSimpleSearchParams.java │ ├── Operation.java │ ├── AuthToken.java │ ├── CountTokensResult.java │ ├── PrebuiltVoiceConfig.java │ ├── LiveServerSetupComplete.java │ ├── GeneratedVideo.java │ ├── StyleReferenceConfig.java │ ├── Mode.java │ ├── ListModelsParameters.java │ ├── NullValue.java │ ├── ScribbleImage.java │ ├── EmbedContentMetadata.java │ ├── ProductImage.java │ ├── GetFileConfig.java │ ├── ListBatchJobsParameters.java │ ├── FileSource.java │ ├── GetModelConfig.java │ ├── StringList.java │ ├── FileState.java │ ├── GetDocumentConfig.java │ ├── GetOperationConfig.java │ ├── LiveServerGoAway.java │ ├── GetBatchJobConfig.java │ ├── Language.java │ ├── ListTuningJobsParameters.java │ ├── DeleteFileConfig.java │ ├── DeleteModelConfig.java │ ├── CancelBatchJobConfig.java │ ├── DownloadFileConfig.java │ ├── GcsDestination.java │ ├── GetTuningJobConfig.java │ ├── ApiAuth.java │ ├── RagRetrievalConfigRankingRankService.java │ ├── ComputeTokensConfig.java │ └── OutputConfig.java │ ├── ApiResponse.java │ ├── ExcludeFromGeneratedCoverageReport.java │ ├── HttpApiResponse.java │ ├── Chats.java │ ├── AsyncChats.java │ ├── AsyncTokens.java │ ├── DebugConfig.java │ └── ReplayApiResponse.java ├── versions.txt ├── releases.txt ├── license-checks.xml ├── release-please-config.json ├── run_shared_tests.sh └── java.header /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | ".": "1.31.0" 3 | } -------------------------------------------------------------------------------- /.github/release-trigger.yml: -------------------------------------------------------------------------------- 1 | enabled: true 2 | multiScmName: java-genai -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | The Google Gen AI SDK will accept contributions in the future. -------------------------------------------------------------------------------- /examples/resources/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/examples/resources/logo.jpg -------------------------------------------------------------------------------- /src/test/resources/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/src/test/resources/logo.jpg -------------------------------------------------------------------------------- /examples/resources/shapes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/examples/resources/shapes.jpg -------------------------------------------------------------------------------- /src/test/resources/bridge1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/src/test/resources/bridge1.png -------------------------------------------------------------------------------- /src/test/resources/google.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/src/test/resources/google.png -------------------------------------------------------------------------------- /src/test/resources/shapes.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/src/test/resources/shapes.jpg -------------------------------------------------------------------------------- /versions.txt: -------------------------------------------------------------------------------- 1 | # Format: 2 | # module:released-version:current-version 3 | 4 | google-genai:1.31.0:1.32.0-SNAPSHOT 5 | -------------------------------------------------------------------------------- /examples/resources/umbrella.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/examples/resources/umbrella.jpg -------------------------------------------------------------------------------- /src/test/resources/umbrella.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/src/test/resources/umbrella.jpg -------------------------------------------------------------------------------- /src/test/resources/checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/src/test/resources/checkerboard.png -------------------------------------------------------------------------------- /examples/resources/watercolor_night_sky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/examples/resources/watercolor_night_sky.jpg -------------------------------------------------------------------------------- /src/test/resources/watercolor_night_sky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/googleapis/java-genai/HEAD/src/test/resources/watercolor_night_sky.jpg -------------------------------------------------------------------------------- /releases.txt: -------------------------------------------------------------------------------- 1 | Use this file when you need to force a patch release with release-please. 2 | Edit line 4 below with the version for the release. 3 | 4 | 1.4.1 5 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/native-image/com.google.genai/google-genai/predefined-classes-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type":"agent-extracted", 4 | "classes":[ 5 | ] 6 | } 7 | ] 8 | 9 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/native-image/com.google.genai/google-genai/serialization-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "types":[ 3 | { 4 | "name":"org.junit.platform.launcher.TestIdentifier$SerializedForm" 5 | } 6 | ], 7 | "lambdaCapturingTypes":[ 8 | ], 9 | "proxies":[ 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /.github/release-please.yml: -------------------------------------------------------------------------------- 1 | handleGHRelease: true 2 | manifest: true 3 | releaseType: maven 4 | bumpMinorPreMajor: true 5 | 6 | branches: 7 | - branch: main 8 | releaseType: maven 9 | handleGHRelease: true 10 | manifest: true 11 | manifestFile: .release-please-manifest.json 12 | manifestConfig: release-please-config.json 13 | -------------------------------------------------------------------------------- /license-checks.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /release-please-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", 3 | "versioning": "always-bump-minor", 4 | "separate-pull-requests": true, 5 | "include-component-in-tag": false, 6 | "bump-minor-pre-major": false, 7 | "bump-patch-for-minor-pre-major": false, 8 | "packages": { 9 | ".": { 10 | "release-type": "java-yoshi", 11 | "extra-files": ["README.md", "src/main/java/com/google/genai/ApiClient.java"], 12 | "changelog-path": "CHANGELOG.md" 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /run_shared_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export GOOGLE_GENAI_CLIENT_MODE=api 4 | export GOOGLE_GENAI_TESTS_SUBDIR=shared 5 | REPLAYS_DIR="$(blaze info workspace 2>/dev/null)/google/cloud/aiplatform/sdk/genai/replays" 6 | export GOOGLE_GENAI_REPLAYS_DIRECTORY="$REPLAYS_DIR" 7 | 8 | echo "Replays directory: $GOOGLE_GENAI_REPLAYS_DIRECTORY" 9 | echo "Client mode: $GOOGLE_GENAI_CLIENT_MODE" 10 | echo "Tests subdirectory: $GOOGLE_GENAI_TESTS_SUBDIR" 11 | echo "Running shared table tests in API mode..." 12 | mvn clean test -Dtest=TableTest -Djacoco.skip=true && mvn clean 13 | -------------------------------------------------------------------------------- /.github/workflows/publish-javadoc.yml: -------------------------------------------------------------------------------- 1 | name: Publish Javadoc 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | permissions: 12 | contents: write 13 | 14 | steps: 15 | - name: Deploy JavaDoc 🚀 16 | uses: MathieuSoysal/Javadoc-publisher.yml@v3.0.2 17 | with: 18 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 19 | javadoc-branch: gh-pages 20 | java-version: 17 21 | target-folder: javadoc 22 | project: maven 23 | custom-command: mvn javadoc:javadoc -------------------------------------------------------------------------------- /java.header: -------------------------------------------------------------------------------- 1 | ^/\*$ 2 | ^ \* Copyright \d\d\d\d,? Google (Inc\.|LLC)$ 3 | ^ \*$ 4 | ^ \* Licensed under the Apache License, Version 2\.0 \(the "License"\);$ 5 | ^ \* you may not use this file except in compliance with the License\.$ 6 | ^ \* You may obtain a copy of the License at$ 7 | ^ \*$ 8 | ^ \*[ ]+https?://www.apache.org/licenses/LICENSE-2\.0$ 9 | ^ \*$ 10 | ^ \* Unless required by applicable law or agreed to in writing, software$ 11 | ^ \* distributed under the License is distributed on an "AS IS" BASIS,$ 12 | ^ \* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\.$ 13 | ^ \* See the License for the specific language governing permissions and$ 14 | ^ \* limitations under the License\.$ 15 | ^ \*/$ -------------------------------------------------------------------------------- /.github/workflows/unit-tests.yml: -------------------------------------------------------------------------------- 1 | name: Java Unit Tests 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | push: 8 | branches: 9 | - main 10 | 11 | jobs: 12 | unit-test: 13 | runs-on: ubuntu-latest 14 | strategy: 15 | matrix: 16 | java: [8, 11, 17, 21] 17 | # Only run unit tests. 18 | testgroup: ["**/*Test"] 19 | fail-fast: false 20 | name: unit-test (${{matrix.java}}) 21 | steps: 22 | - uses: actions/checkout@v4 23 | - uses: actions/setup-java@v4 24 | with: 25 | distribution: 'temurin' 26 | java-version: ${{matrix.java}} 27 | cache: 'maven' 28 | - name: Java Unit Tests 29 | run: mvn clean test -Dtest=${{matrix.testgroup}} -Djacoco.skip=true -------------------------------------------------------------------------------- /src/main/resources/META-INF/native-image/com.google.genai/google-genai/jni-config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name":"sun.instrument.InstrumentationImpl", 4 | "methods":[{"name":"","parameterTypes":["long","boolean","boolean","boolean"] }, {"name":"loadClassAndCallAgentmain","parameterTypes":["java.lang.String","java.lang.String"] }, {"name":"loadClassAndCallPremain","parameterTypes":["java.lang.String","java.lang.String"] }, {"name":"transform","parameterTypes":["java.lang.Module","java.lang.ClassLoader","java.lang.String","java.lang.Class","java.security.ProtectionDomain","byte[]","boolean"] }] 5 | }, 6 | { 7 | "name":"sun.management.VMManagementImpl", 8 | "fields":[{"name":"compTimeMonitoringSupport"}, {"name":"currentThreadCpuTimeSupport"}, {"name":"objectMonitorUsageSupport"}, {"name":"otherThreadCpuTimeSupport"}, {"name":"remoteDiagnosticCommandsSupport"}, {"name":"synchronizerUsageSupport"}, {"name":"threadAllocatedMemorySupport"}, {"name":"threadContentionMonitoringSupport"}] 9 | } 10 | ] 11 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/errors/ClientException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.errors; 18 | 19 | /** Client exception raised by the GenAI API. */ 20 | public final class ClientException extends ApiException { 21 | 22 | /** Creates a new ClientException with the specified message. */ 23 | public ClientException(int code, String status, String message) { 24 | super(code, status, message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/errors/ServerException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.errors; 18 | 19 | /** Server exception raised by the GenAI API. */ 20 | public final class ServerException extends ApiException { 21 | 22 | /** Creates a new ServerException with the specified message. */ 23 | public ServerException(int code, String status, String message) { 24 | super(code, status, message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ReferenceImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.types; 18 | 19 | /** 20 | * An interface for a Reference image. 21 | * 22 | *

The 5 types of reference images are: {@link com.google.genai.types.RawReferenceImage}, {@link 23 | * com.google.genai.types.MaskReferenceImage}, {@link com.google.genai.types.ControlReferenceImage}, 24 | * {@link com.google.genai.types.StyleReferenceImage}, {@link 25 | * com.google.genai.types.SubjectReferenceImage}, 26 | */ 27 | public interface ReferenceImage { 28 | public ReferenceImageAPI toReferenceImageAPI(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/ApiResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import com.google.api.core.InternalApi; 20 | import okhttp3.Headers; 21 | import okhttp3.ResponseBody; 22 | 23 | /** The API response contains a response to a call to the GenAI APIs. */ 24 | @InternalApi 25 | public abstract class ApiResponse implements AutoCloseable { 26 | /** Gets the ResponseBody. */ 27 | public abstract ResponseBody getBody(); 28 | 29 | /** Returns all of the headers from the response. */ 30 | public abstract Headers getHeaders(); 31 | 32 | @Override 33 | public abstract void close(); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/ExcludeFromGeneratedCoverageReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Annotation to exclude a method or constructor from the Jacoco coverage report. 26 | * 27 | *

Jacoco will exclude methods that have an annotation with the word "generated" in it. 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) 31 | @interface ExcludeFromGeneratedCoverageReport {} 32 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/errors/ExcludeFromGeneratedCoverageReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.errors; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Annotation to exclude a method or constructor from the Jacoco coverage report. 26 | * 27 | *

Jacoco will exclude methods that have an annotation with the word "generated" in it. 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) 31 | @interface ExcludeFromGeneratedCoverageReport {} -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ExcludeFromGeneratedCoverageReport.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.types; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * Annotation to exclude a method or constructor from the Jacoco coverage report. 26 | * 27 | *

Jacoco will exclude methods that have an annotation with the word "generated" in it. 28 | */ 29 | @Retention(RetentionPolicy.CLASS) 30 | @Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE}) 31 | @interface ExcludeFromGeneratedCoverageReport {} 32 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | # This workflow warns and then closes issues that have had no activity for a specified amount of time. 2 | name: Mark and close stale issues 3 | 4 | on: 5 | schedule: 6 | # Scheduled to run at 1:30 UTC everyday 7 | - cron: '30 1 * * *' 8 | 9 | jobs: 10 | stale: 11 | 12 | runs-on: ubuntu-latest 13 | permissions: 14 | issues: write 15 | 16 | steps: 17 | - uses: actions/stale@v5 18 | with: 19 | repo-token: ${{ secrets.GITHUB_TOKEN }} 20 | days-before-issue-stale: 7 21 | days-before-issue-close: 2 22 | stale-issue-label: "status:stale" 23 | close-issue-reason: not_planned 24 | any-of-labels: "status:awaiting user response" 25 | remove-stale-when-updated: true 26 | labels-to-remove-when-unstale: 'status:awaiting user response,status:stale' 27 | stale-issue-message: > 28 | This issue has been marked as stale because it has been open for 7 days with no activity. It will be closed in 2 days if no further activity occurs. 29 | close-issue-message: > 30 | This issue was closed because it has been inactive for 9 days. 31 | Please post a new issue if you need further assistance. Thanks! 32 | # Label that can be assigned to issues to exclude them from being marked as stale 33 | exempt-issue-labels: 'override-stale' 34 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/LocalCountTokens.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Usage: 19 | * 20 | *

1. Compile the java package and run the sample code. 21 | * 22 | *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.LocalCountTokens" 23 | */ 24 | package com.google.genai.examples; 25 | 26 | import com.google.genai.LocalTokenizer; 27 | 28 | /** An example of using the Unified Gen AI Java SDK to count tokens locally. */ 29 | public class LocalCountTokens { 30 | public static void main(String[] args) { 31 | LocalTokenizer tokenizer = new LocalTokenizer(Constants.GEMINI_MODEL_NAME); 32 | System.out.println( 33 | "Count for 'Hello world': " + tokenizer.countTokens("Hello world").totalTokens()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/FakeApiResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import okhttp3.Headers; 20 | import okhttp3.ResponseBody; 21 | 22 | /** */ 23 | public final class FakeApiResponse extends ApiResponse { 24 | 25 | private final Headers headers; 26 | private final ResponseBody body; 27 | 28 | public FakeApiResponse(Headers headers, ResponseBody body) { 29 | this.headers = headers; 30 | this.body = body; 31 | } 32 | 33 | @Override 34 | public Headers getHeaders() { 35 | return headers; 36 | } 37 | 38 | @Override 39 | public ResponseBody getBody() { 40 | return body; 41 | } 42 | 43 | @Override 44 | public void close() { 45 | throw new UnsupportedOperationException("Not implemented yet."); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/LocalComputeTokens.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Usage: 19 | * 20 | *

1. Compile the java package and run the sample code. 21 | * 22 | *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.LocalComputeTokens" 23 | */ 24 | package com.google.genai.examples; 25 | 26 | import com.google.genai.LocalTokenizer; 27 | 28 | /** An example of using the Unified Gen AI Java SDK to compute tokens locally. */ 29 | public class LocalComputeTokens { 30 | public static void main(String[] args) { 31 | LocalTokenizer tokenizer = new LocalTokenizer(Constants.GEMINI_MODEL_NAME); 32 | System.out.println( 33 | "Compute tokens for 'Hello world': " + tokenizer.computeTokens("Hello world").toJson()); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/errors/GenAiIOException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.errors; 18 | 19 | import java.io.IOException; 20 | 21 | /** IO exception raised in the GenAI SDK. */ 22 | public final class GenAiIOException extends BaseException { 23 | 24 | /** Creates a new GenAiIoException with the specified message and the original IOException. */ 25 | public GenAiIOException(String message, IOException cause) { 26 | super(message, cause); 27 | } 28 | 29 | /** Creates a new GenAiIoException with the specified message. */ 30 | public GenAiIOException(String message) { 31 | super(message); 32 | } 33 | 34 | /** Creates a new GenAiIoException with the specified cause. */ 35 | public GenAiIOException(Throwable cause) { 36 | super(cause.getMessage(), cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/errors/BaseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.errors; 18 | 19 | /** 20 | * Base exception class for all exceptions specifically originating from the GenAI SDK. 21 | * 22 | *

This class extends {@link RuntimeException}. The GenAI SDK favors unchecked exceptions 23 | * to improve developer experience by reducing mandatory {@code try-catch} or {@code throws} 24 | * clause boilerplate for potentially unrecoverable runtime errors. 25 | */ 26 | class BaseException extends RuntimeException { 27 | 28 | /** Creates a new exception with the specified message. */ 29 | BaseException(String message) { 30 | super(message); 31 | } 32 | 33 | /** Creates a new exception with the specified message and cause. */ 34 | BaseException(String message, Throwable cause) { 35 | super(message, cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/types/FunctionResponsePartTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.types; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | public class FunctionResponsePartTest { 24 | 25 | @Test 26 | public void testFunctionResponsePartFromUri() { 27 | FunctionResponsePart part = FunctionResponsePart.fromUri("test-uri", "test-mime-type"); 28 | 29 | assertEquals("test-uri", part.fileData().get().fileUri().get()); 30 | assertEquals("test-mime-type", part.fileData().get().mimeType().get()); 31 | } 32 | 33 | @Test 34 | public void testPartFromBytes() { 35 | byte[] bytes = new byte[] {1, 2, 3}; 36 | FunctionResponsePart part = 37 | FunctionResponsePart.fromBytes(bytes, "test-mime-type"); 38 | 39 | assertEquals(bytes, part.inlineData().get().data().get()); 40 | assertEquals("test-mime-type", part.inlineData().get().mimeType().get()); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/HttpApiResponse.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import com.google.genai.errors.ApiException; 20 | import okhttp3.Headers; 21 | import okhttp3.Response; 22 | import okhttp3.ResponseBody; 23 | 24 | /** Wraps a real HTTP response to expose the methods needed by the GenAI SDK. */ 25 | final class HttpApiResponse extends ApiResponse { 26 | 27 | private final Response response; 28 | 29 | /** Constructs a HttpApiResponse instance with the response. */ 30 | public HttpApiResponse(Response response) { 31 | this.response = response; 32 | } 33 | 34 | /** Returns the ResponseBody from the response. */ 35 | @Override 36 | public ResponseBody getBody() { 37 | ApiException.throwFromResponse(response); 38 | return response.body(); 39 | } 40 | 41 | /** Returns all of the headers from the response. */ 42 | @Override 43 | public Headers getHeaders() { 44 | return response.headers(); 45 | } 46 | 47 | /** Closes the Http response. */ 48 | @Override 49 | public void close() { 50 | response.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/Chats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import com.google.genai.types.GenerateContentConfig; 20 | 21 | /** A class for creating chat sessions. */ 22 | public class Chats { 23 | private final ApiClient apiClient; 24 | 25 | Chats(ApiClient apiClient) { 26 | this.apiClient = apiClient; 27 | } 28 | 29 | /** 30 | * Creates a new chat session. 31 | * 32 | * @param model The model to use for the chat session. 33 | * @param config The configuration for the chat session. 34 | * @return The chat session. 35 | */ 36 | public Chat create(String model, GenerateContentConfig config) { 37 | return privateCreate(model, config); 38 | } 39 | 40 | /** 41 | * Creates a new chat session. 42 | * 43 | * @param model The model to use for the chat session. 44 | * @return The chat session. 45 | */ 46 | public Chat create(String model) { 47 | return privateCreate(model, null); 48 | } 49 | 50 | private Chat privateCreate(String model, GenerateContentConfig config) { 51 | return new Chat(apiClient, model, config); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/AsyncChats.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import com.google.genai.types.GenerateContentConfig; 20 | 21 | /** A class for creating async chat sessions. */ 22 | public class AsyncChats { 23 | private final ApiClient apiClient; 24 | 25 | AsyncChats(ApiClient apiClient) { 26 | this.apiClient = apiClient; 27 | } 28 | 29 | /** 30 | * Creates a new async chat session. 31 | * 32 | * @param model The model to use for the async chat session. 33 | * @param config The configuration for the async chat session. 34 | * @return The async chat session. 35 | */ 36 | public AsyncChat create(String model, GenerateContentConfig config) { 37 | return privateCreate(model, config); 38 | } 39 | 40 | /** 41 | * Creates a new async chat session. 42 | * 43 | * @param model The model to use for the async chat session. 44 | * @return The async chat session. 45 | */ 46 | public AsyncChat create(String model) { 47 | return privateCreate(model, null); 48 | } 49 | 50 | private AsyncChat privateCreate(String model, GenerateContentConfig config) { 51 | return new AsyncChat(apiClient, model, config); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/TestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | public final class TestUtils { 20 | static final String API_KEY = "api-key"; 21 | static final String PROJECT = "project"; 22 | static final String LOCATION = "location"; 23 | 24 | private TestUtils() {} 25 | 26 | /** Creates a client given the vertexAI and replayId. Can be used in replay tests. */ 27 | public static Client createClient(boolean vertexAI, String replayId) { 28 | String clientMode = System.getenv("GOOGLE_GENAI_CLIENT_MODE"); 29 | DebugConfig debugConfig = 30 | new DebugConfig( 31 | clientMode == null ? "replay" : clientMode, 32 | "", 33 | System.getenv("GOOGLE_GENAI_REPLAYS_DIRECTORY")); 34 | 35 | Client.Builder clientBuilder = Client.builder().vertexAI(vertexAI).debugConfig(debugConfig); 36 | 37 | if (vertexAI) { 38 | clientBuilder.project(PROJECT).location(LOCATION); 39 | } else { 40 | clientBuilder.apiKey(API_KEY); 41 | } 42 | Client client = clientBuilder.build(); 43 | 44 | if (client.clientMode().equals("replay")) { 45 | client.setReplayId(replayId); 46 | } 47 | return client; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/ReplayBase64Sanitizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import java.util.Base64; 20 | 21 | public class ReplayBase64Sanitizer implements ReplaySanitizer.Sanitizer { 22 | 23 | @Override 24 | public Object sanitize(Object obj, String path) { 25 | if (obj instanceof String) { 26 | String str = (String) obj; 27 | 28 | try { 29 | // 1. Attempt URL-safe Base64 decoding 30 | byte[] decoded = Base64.getUrlDecoder().decode(str); 31 | // If URL-safe decoding succeeds, encode back to standard Base64 32 | return Base64.getEncoder().encodeToString(decoded); 33 | 34 | } catch (IllegalArgumentException e1) { 35 | try { 36 | // 2. If URL-safe decoding fails, attempt standard Base64 decoding 37 | byte[] decoded = Base64.getDecoder().decode(str); 38 | return Base64.getEncoder() 39 | .encodeToString(decoded); // Encode back to standard Base64 for consistency 40 | 41 | } catch (IllegalArgumentException e2) { 42 | // 3. If both fail, it's not a valid Base64 string. 43 | throw e2; 44 | } 45 | } 46 | } 47 | return obj; // If it's not a string, return the object as is 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/AsyncTokens.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import com.google.genai.Common.BuiltRequest; 20 | import com.google.genai.types.AuthToken; 21 | import com.google.genai.types.CreateAuthTokenConfig; 22 | import java.util.concurrent.CompletableFuture; 23 | 24 | /** Async module of {@link AuthToken} */ 25 | public final class AsyncTokens { 26 | 27 | Tokens tokens; 28 | ApiClient apiClient; 29 | 30 | public AsyncTokens(ApiClient apiClient) { 31 | this.apiClient = apiClient; 32 | this.tokens = new Tokens(apiClient); 33 | } 34 | 35 | /** 36 | * Asynchronously creates an ephemeral auth token resource. 37 | * 38 | * @param config A {@link CreateAuthTokenConfig} for configuring the create request. 39 | * @return A {@link AuthToken} object that contains the info of the created resource. 40 | */ 41 | public CompletableFuture create(CreateAuthTokenConfig config) { 42 | BuiltRequest builtRequest = tokens.buildRequestForCreate(config); 43 | return this.apiClient 44 | .asyncRequest("post", builtRequest.path, builtRequest.body, builtRequest.httpOptions) 45 | .thenApplyAsync( 46 | response -> { 47 | try (ApiResponse res = response) { 48 | return tokens.processResponseForCreate(res, config); 49 | } 50 | }); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/UrlContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.google.auto.value.AutoValue; 24 | import com.google.genai.JsonSerializable; 25 | 26 | /** Tool to support URL context. */ 27 | @AutoValue 28 | @JsonDeserialize(builder = UrlContext.Builder.class) 29 | public abstract class UrlContext extends JsonSerializable { 30 | /** Instantiates a builder for UrlContext. */ 31 | @ExcludeFromGeneratedCoverageReport 32 | public static Builder builder() { 33 | return new AutoValue_UrlContext.Builder(); 34 | } 35 | 36 | /** Creates a builder with the same values as this instance. */ 37 | public abstract Builder toBuilder(); 38 | 39 | /** Builder for UrlContext. */ 40 | @AutoValue.Builder 41 | public abstract static class Builder { 42 | /** For internal usage. Please use `UrlContext.builder()` for instantiation. */ 43 | @JsonCreator 44 | private static Builder create() { 45 | return new AutoValue_UrlContext.Builder(); 46 | } 47 | 48 | public abstract UrlContext build(); 49 | } 50 | 51 | /** Deserializes a JSON string to a UrlContext object. */ 52 | @ExcludeFromGeneratedCoverageReport 53 | public static UrlContext fromJson(String jsonString) { 54 | return JsonSerializable.fromJsonString(jsonString, UrlContext.class); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /examples/resources/test.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos. 2 | 3 | Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos. 4 | 5 | Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos. 6 | 7 | Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos. 8 | 9 | Lorem ipsum dolor sit amet consectetur adipiscing elit. Quisque faucibus ex sapien vitae pellentesque sem placerat. In id cursus mi pretium tellus duis convallis. Tempus leo eu aenean sed diam urna tempor. Pulvinar vivamus fringilla lacus nec metus bibendum egestas. Iaculis massa nisl malesuada lacinia integer nunc posuere. Ut hendrerit semper vel class aptent taciti sociosqu. Ad litora torquent per conubia nostra inceptos himenaeos. -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ActivityEnd.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.google.auto.value.AutoValue; 24 | import com.google.genai.JsonSerializable; 25 | 26 | /** 27 | * Marks the end of user activity. 28 | * 29 | *

This can only be sent if automatic (i.e. server-side) activity detection is disabled. 30 | */ 31 | @AutoValue 32 | @JsonDeserialize(builder = ActivityEnd.Builder.class) 33 | public abstract class ActivityEnd extends JsonSerializable { 34 | /** Instantiates a builder for ActivityEnd. */ 35 | @ExcludeFromGeneratedCoverageReport 36 | public static Builder builder() { 37 | return new AutoValue_ActivityEnd.Builder(); 38 | } 39 | 40 | /** Creates a builder with the same values as this instance. */ 41 | public abstract Builder toBuilder(); 42 | 43 | /** Builder for ActivityEnd. */ 44 | @AutoValue.Builder 45 | public abstract static class Builder { 46 | /** For internal usage. Please use `ActivityEnd.builder()` for instantiation. */ 47 | @JsonCreator 48 | private static Builder create() { 49 | return new AutoValue_ActivityEnd.Builder(); 50 | } 51 | 52 | public abstract ActivityEnd build(); 53 | } 54 | 55 | /** Deserializes a JSON string to a ActivityEnd object. */ 56 | @ExcludeFromGeneratedCoverageReport 57 | public static ActivityEnd fromJson(String jsonString) { 58 | return JsonSerializable.fromJsonString(jsonString, ActivityEnd.class); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ActivityStart.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.google.auto.value.AutoValue; 24 | import com.google.genai.JsonSerializable; 25 | 26 | /** 27 | * Marks the start of user activity. 28 | * 29 | *

This can only be sent if automatic (i.e. server-side) activity detection is disabled. 30 | */ 31 | @AutoValue 32 | @JsonDeserialize(builder = ActivityStart.Builder.class) 33 | public abstract class ActivityStart extends JsonSerializable { 34 | /** Instantiates a builder for ActivityStart. */ 35 | @ExcludeFromGeneratedCoverageReport 36 | public static Builder builder() { 37 | return new AutoValue_ActivityStart.Builder(); 38 | } 39 | 40 | /** Creates a builder with the same values as this instance. */ 41 | public abstract Builder toBuilder(); 42 | 43 | /** Builder for ActivityStart. */ 44 | @AutoValue.Builder 45 | public abstract static class Builder { 46 | /** For internal usage. Please use `ActivityStart.builder()` for instantiation. */ 47 | @JsonCreator 48 | private static Builder create() { 49 | return new AutoValue_ActivityStart.Builder(); 50 | } 51 | 52 | public abstract ActivityStart build(); 53 | } 54 | 55 | /** Deserializes a JSON string to a ActivityStart object. */ 56 | @ExcludeFromGeneratedCoverageReport 57 | public static ActivityStart fromJson(String jsonString) { 58 | return JsonSerializable.fromJsonString(jsonString, ActivityStart.class); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/AudioTranscriptionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.google.auto.value.AutoValue; 24 | import com.google.genai.JsonSerializable; 25 | 26 | /** The audio transcription configuration in Setup. */ 27 | @AutoValue 28 | @JsonDeserialize(builder = AudioTranscriptionConfig.Builder.class) 29 | public abstract class AudioTranscriptionConfig extends JsonSerializable { 30 | /** Instantiates a builder for AudioTranscriptionConfig. */ 31 | @ExcludeFromGeneratedCoverageReport 32 | public static Builder builder() { 33 | return new AutoValue_AudioTranscriptionConfig.Builder(); 34 | } 35 | 36 | /** Creates a builder with the same values as this instance. */ 37 | public abstract Builder toBuilder(); 38 | 39 | /** Builder for AudioTranscriptionConfig. */ 40 | @AutoValue.Builder 41 | public abstract static class Builder { 42 | /** For internal usage. Please use `AudioTranscriptionConfig.builder()` for instantiation. */ 43 | @JsonCreator 44 | private static Builder create() { 45 | return new AutoValue_AudioTranscriptionConfig.Builder(); 46 | } 47 | 48 | public abstract AudioTranscriptionConfig build(); 49 | } 50 | 51 | /** Deserializes a JSON string to a AudioTranscriptionConfig object. */ 52 | @ExcludeFromGeneratedCoverageReport 53 | public static AudioTranscriptionConfig fromJson(String jsonString) { 54 | return JsonSerializable.fromJsonString(jsonString, AudioTranscriptionConfig.class); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/errors/GenAiIOExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.errors; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import java.io.IOException; 23 | import org.junit.jupiter.api.Test; 24 | 25 | class GenAiIOExceptionTest { 26 | 27 | @Test 28 | public void testInitGenAiIOException_withMessage() { 29 | try { 30 | throw new GenAiIOException("Error message"); 31 | } catch (GenAiIOException e) { 32 | assertTrue(e instanceof BaseException); 33 | assertTrue(e instanceof RuntimeException); 34 | assertEquals("Error message", e.getMessage()); 35 | } 36 | } 37 | 38 | @Test 39 | public void testInitGenAiIOException_withCause() { 40 | try { 41 | throw new GenAiIOException(new IOException("i/o exception")); 42 | } catch (GenAiIOException e) { 43 | assertTrue(e instanceof BaseException); 44 | assertTrue(e instanceof RuntimeException); 45 | assertEquals("i/o exception", e.getMessage()); 46 | assertTrue(e.getCause() instanceof IOException); 47 | } 48 | } 49 | 50 | @Test 51 | public void testInitGenAiIOException_withMessageAndCause() { 52 | try { 53 | throw new GenAiIOException("Error message", new IOException("i/o exception")); 54 | } catch (GenAiIOException e) { 55 | assertTrue(e instanceof BaseException); 56 | assertTrue(e instanceof RuntimeException); 57 | assertEquals("Error message", e.getMessage()); 58 | assertEquals("i/o exception", e.getCause().getMessage()); 59 | assertTrue(e.getCause() instanceof IOException); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/DebugConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | /** Data class configuration for debugging or testing the Client. */ 20 | @ExcludeFromGeneratedCoverageReport 21 | final class DebugConfig { 22 | private final String clientMode; 23 | private final String replayId; 24 | private final String replaysDirectory; 25 | 26 | DebugConfig() { 27 | String clientMode = System.getenv("GOOGLE_GENAI_CLIENT_MODE"); 28 | this.clientMode = clientMode != null ? clientMode : ""; 29 | 30 | String replayId = System.getenv("GOOGLE_GENAI_REPLAY_ID"); 31 | this.replayId = replayId != null ? replayId : ""; 32 | 33 | String replaysDirectory = System.getenv("GOOGLE_GENAI_REPLAYS_DIRECTORY"); 34 | this.replaysDirectory = replaysDirectory != null ? replaysDirectory : ""; 35 | } 36 | 37 | DebugConfig(String clientMode, String replayId, String replaysDirectory) { 38 | String envClientMode = System.getenv("GOOGLE_GENAI_CLIENT_MODE"); 39 | this.clientMode = 40 | clientMode != null ? clientMode : (envClientMode != null ? envClientMode : ""); 41 | 42 | String envReplayId = System.getenv("GOOGLE_GENAI_REPLAY_ID"); 43 | this.replayId = replayId != null ? replayId : (envReplayId != null ? envReplayId : ""); 44 | 45 | String envReplaysDirectory = System.getenv("GOOGLE_GENAI_REPLAYS_DIRECTORY"); 46 | this.replaysDirectory = 47 | replaysDirectory != null 48 | ? replaysDirectory 49 | : (envReplaysDirectory != null ? envReplaysDirectory : ""); 50 | } 51 | 52 | public String clientMode() { 53 | return this.clientMode; 54 | } 55 | 56 | public String replayId() { 57 | return this.replayId; 58 | } 59 | 60 | public String replaysDirectory() { 61 | return this.replaysDirectory; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ToolCodeExecution.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.google.auto.value.AutoValue; 24 | import com.google.genai.JsonSerializable; 25 | 26 | /** 27 | * Tool that executes code generated by the model, and automatically returns the result to the 28 | * model. See also [ExecutableCode]and [CodeExecutionResult] which are input and output to this 29 | * tool. This data type is not supported in Gemini API. 30 | */ 31 | @AutoValue 32 | @JsonDeserialize(builder = ToolCodeExecution.Builder.class) 33 | public abstract class ToolCodeExecution extends JsonSerializable { 34 | /** Instantiates a builder for ToolCodeExecution. */ 35 | @ExcludeFromGeneratedCoverageReport 36 | public static Builder builder() { 37 | return new AutoValue_ToolCodeExecution.Builder(); 38 | } 39 | 40 | /** Creates a builder with the same values as this instance. */ 41 | public abstract Builder toBuilder(); 42 | 43 | /** Builder for ToolCodeExecution. */ 44 | @AutoValue.Builder 45 | public abstract static class Builder { 46 | /** For internal usage. Please use `ToolCodeExecution.builder()` for instantiation. */ 47 | @JsonCreator 48 | private static Builder create() { 49 | return new AutoValue_ToolCodeExecution.Builder(); 50 | } 51 | 52 | public abstract ToolCodeExecution build(); 53 | } 54 | 55 | /** Deserializes a JSON string to a ToolCodeExecution object. */ 56 | @ExcludeFromGeneratedCoverageReport 57 | public static ToolCodeExecution fromJson(String jsonString) { 58 | return JsonSerializable.fromJsonString(jsonString, ToolCodeExecution.class); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ExternalApiSimpleSearchParams.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 23 | import com.google.auto.value.AutoValue; 24 | import com.google.genai.JsonSerializable; 25 | 26 | /** 27 | * The search parameters to use for SIMPLE_SEARCH spec. This data type is not supported in Gemini 28 | * API. 29 | */ 30 | @AutoValue 31 | @JsonDeserialize(builder = ExternalApiSimpleSearchParams.Builder.class) 32 | public abstract class ExternalApiSimpleSearchParams extends JsonSerializable { 33 | /** Instantiates a builder for ExternalApiSimpleSearchParams. */ 34 | @ExcludeFromGeneratedCoverageReport 35 | public static Builder builder() { 36 | return new AutoValue_ExternalApiSimpleSearchParams.Builder(); 37 | } 38 | 39 | /** Creates a builder with the same values as this instance. */ 40 | public abstract Builder toBuilder(); 41 | 42 | /** Builder for ExternalApiSimpleSearchParams. */ 43 | @AutoValue.Builder 44 | public abstract static class Builder { 45 | /** 46 | * For internal usage. Please use `ExternalApiSimpleSearchParams.builder()` for instantiation. 47 | */ 48 | @JsonCreator 49 | private static Builder create() { 50 | return new AutoValue_ExternalApiSimpleSearchParams.Builder(); 51 | } 52 | 53 | public abstract ExternalApiSimpleSearchParams build(); 54 | } 55 | 56 | /** Deserializes a JSON string to a ExternalApiSimpleSearchParams object. */ 57 | @ExcludeFromGeneratedCoverageReport 58 | public static ExternalApiSimpleSearchParams fromJson(String jsonString) { 59 | return JsonSerializable.fromJsonString(jsonString, ExternalApiSimpleSearchParams.class); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/types/VideoMetadataTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.types; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.assertFalse; 21 | import static org.junit.jupiter.api.Assertions.assertTrue; 22 | 23 | import java.time.Duration; 24 | import org.junit.jupiter.api.Test; 25 | 26 | public class VideoMetadataTest { 27 | 28 | @Test 29 | public void testSerializationDeserialization_withDurations() { 30 | Duration start = Duration.ofSeconds(60); 31 | Duration end = Duration.ofSeconds(125); 32 | 33 | VideoMetadata original = 34 | VideoMetadata.builder().startOffset(start).endOffset(end).build(); 35 | 36 | // Test serialization 37 | String json = original.toJson(); 38 | assertTrue(json.contains("\"startOffset\":\"60s\"")); 39 | assertTrue(json.contains("\"endOffset\":\"125s\"")); 40 | 41 | // Test deserialization 42 | VideoMetadata deserialized = VideoMetadata.fromJson(json); 43 | assertTrue(deserialized.startOffset().isPresent()); 44 | assertEquals(start, deserialized.startOffset().get()); 45 | assertTrue(deserialized.endOffset().isPresent()); 46 | assertEquals(end, deserialized.endOffset().get()); 47 | } 48 | 49 | @Test 50 | public void testSerializationDeserialization_nullDurations() { 51 | VideoMetadata original = VideoMetadata.builder().build(); 52 | 53 | // Test serialization 54 | String json = original.toJson(); 55 | // Should not contain the fields due to JsonInclude.Include.NON_ABSENT 56 | assertFalse(json.contains("startOffset")); 57 | assertFalse(json.contains("endOffset")); 58 | 59 | // Test deserialization 60 | VideoMetadata deserialized = VideoMetadata.fromJson(json); 61 | assertFalse(deserialized.startOffset().isPresent()); 62 | assertFalse(deserialized.endOffset().isPresent()); 63 | } 64 | } -------------------------------------------------------------------------------- /src/test/java/com/google/genai/NativeImageReflectionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import com.google.genai.types.*; 20 | import org.junit.jupiter.api.Test; 21 | 22 | /** 23 | * Test to generate comprehensive reflection metadata for native image. 24 | * This test instantiates all builder types to ensure they're captured by the agent. 25 | */ 26 | public class NativeImageReflectionTest { 27 | 28 | @Test 29 | public void testAllBuilderTypes() { 30 | // Exercise all the builder types that might be used in streaming responses 31 | try { 32 | // FunctionResponsePart and related types 33 | FunctionResponseBlob.builder().build(); 34 | FunctionResponseFileData.builder().build(); 35 | FunctionResponsePart.builder().build(); 36 | 37 | // Content and Part types 38 | Content.builder().build(); 39 | Part.builder().build(); 40 | 41 | // Response types 42 | GenerateContentResponse.builder().build(); 43 | Candidate.builder().build(); 44 | 45 | // Safety and metadata types 46 | SafetyRating.builder().build(); 47 | CitationMetadata.builder().build(); 48 | 49 | // Usage metadata 50 | UsageMetadata.builder().build(); 51 | 52 | // Grounding metadata 53 | GroundingMetadata.builder().build(); 54 | GroundingChunk.builder().build(); 55 | 56 | // Model types 57 | Model.builder().build(); 58 | 59 | } catch (Exception e) { 60 | // Expected - we're just ensuring reflection metadata is generated 61 | } 62 | } 63 | 64 | @Test 65 | public void testDeserializationTypes() { 66 | // Test JSON deserialization to ensure Jackson reflection is captured 67 | try { 68 | String jsonResponse = "{\"candidates\":[{\"content\":{\"parts\":[{\"text\":\"test\"}]}}]}"; 69 | GenerateContentResponse.fromJson(jsonResponse); 70 | 71 | String jsonPart = "{\"inlineData\":{\"mimeType\":\"text/plain\",\"data\":\"test\"}}"; 72 | FunctionResponsePart.fromJson(jsonPart); 73 | 74 | } catch (Exception e) { 75 | // Expected - we're just ensuring reflection metadata is generated 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/Operation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonProperty; 22 | import com.fasterxml.jackson.databind.JsonNode; 23 | import com.google.genai.JsonSerializable; 24 | import java.util.Map; 25 | import java.util.Optional; 26 | 27 | /** A long-running operation. */ 28 | public abstract class Operation> extends JsonSerializable { 29 | /** 30 | * The server-assigned name, which is only unique within the same service that originally returns 31 | * it. If you use the default HTTP mapping, the `name` should be a resource name ending with 32 | * `operations/{unique_id}`. 33 | */ 34 | @JsonProperty("name") 35 | public abstract Optional name(); 36 | 37 | /** 38 | * Service-specific metadata associated with the operation. It typically contains progress 39 | * information and common metadata such as create time. Some services might not provide such 40 | * metadata. Any method that returns a long-running operation should document the metadata type, 41 | * if any. 42 | */ 43 | @JsonProperty("metadata") 44 | public abstract Optional> metadata(); 45 | 46 | /** 47 | * If the value is `false`, it means the operation is still in progress. If `true`, the operation 48 | * is completed, and either `error` or `response` is available. 49 | */ 50 | @JsonProperty("done") 51 | public abstract Optional done(); 52 | 53 | /** The error result of the operation in case of failure or cancellation. */ 54 | @JsonProperty("error") 55 | public abstract Optional> error(); 56 | 57 | /** The result of the operation. */ 58 | @JsonProperty("response") 59 | public abstract Optional response(); 60 | 61 | /** 62 | * Creates a new Operation object from an API response. 63 | * 64 | * @param apiResponse The API response. 65 | * @param isVertexAi Whether the API response is from Vertex AI. 66 | * @return The new Operation object. 67 | */ 68 | public abstract O fromApiResponse(JsonNode apiResponse, boolean isVertexAi); 69 | } 70 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/AsyncTokensTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; 20 | import static org.junit.jupiter.api.Assertions.assertNotNull; 21 | import static org.junit.jupiter.api.Assertions.assertThrows; 22 | 23 | import com.google.genai.types.AuthToken; 24 | import com.google.genai.types.CreateAuthTokenConfig; 25 | import com.google.genai.types.HttpOptions; 26 | import java.util.concurrent.ExecutionException; 27 | import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; 28 | import org.junit.jupiter.api.extension.ExtendWith; 29 | import org.junit.jupiter.params.ParameterizedTest; 30 | import org.junit.jupiter.params.provider.ValueSource; 31 | 32 | @EnabledIfEnvironmentVariable( 33 | named = "GOOGLE_GENAI_REPLAYS_DIRECTORY", 34 | matches = ".*genai/replays.*") 35 | @ExtendWith(EnvironmentVariablesMockingExtension.class) 36 | public class AsyncTokensTest { 37 | @ParameterizedTest 38 | @ValueSource(booleans = {false, true}) 39 | public void testAsyncCreateAuthToken(boolean vertexAI) 40 | throws ExecutionException, InterruptedException { 41 | // Arrange 42 | String suffix = vertexAI ? "vertex" : "mldev"; 43 | Client client = 44 | TestUtils.createClient( 45 | vertexAI, "tests/tokens/create/test_async_create_no_lock." + suffix + ".json"); 46 | 47 | CreateAuthTokenConfig config = 48 | CreateAuthTokenConfig.builder() 49 | .httpOptions( 50 | HttpOptions.builder().apiVersion("v1alpha").build()) 51 | .build(); 52 | 53 | // Act 54 | if (vertexAI) { 55 | UnsupportedOperationException exception = 56 | assertThrows( 57 | UnsupportedOperationException.class, 58 | () -> client.async.authTokens.create(CreateAuthTokenConfig.builder().build()).get()); 59 | assertEquals( 60 | "This method is only supported in the Gemini Developer client.", exception.getMessage()); 61 | } else { 62 | AuthToken response = client.async.authTokens.create(config).get(); 63 | 64 | // Assert 65 | assertNotNull(response); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/AuthToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Config for auth_tokens.create parameters. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = AuthToken.Builder.class) 32 | public abstract class AuthToken extends JsonSerializable { 33 | /** The name of the auth token. */ 34 | @JsonProperty("name") 35 | public abstract Optional name(); 36 | 37 | /** Instantiates a builder for AuthToken. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_AuthToken.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for AuthToken. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `AuthToken.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_AuthToken.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for name. 57 | * 58 | *

name: The name of the auth token. 59 | */ 60 | @JsonProperty("name") 61 | public abstract Builder name(String name); 62 | 63 | @ExcludeFromGeneratedCoverageReport 64 | abstract Builder name(Optional name); 65 | 66 | /** Clears the value of name field. */ 67 | @ExcludeFromGeneratedCoverageReport 68 | @CanIgnoreReturnValue 69 | public Builder clearName() { 70 | return name(Optional.empty()); 71 | } 72 | 73 | public abstract AuthToken build(); 74 | } 75 | 76 | /** Deserializes a JSON string to a AuthToken object. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | public static AuthToken fromJson(String jsonString) { 79 | return JsonSerializable.fromJsonString(jsonString, AuthToken.class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 4.0.0 5 | 6 | com.google.genai.examples 7 | google-genai-examples 8 | 1.32.0-SNAPSHOT 9 | google-genai-examples 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 1.8 15 | 16 | 1.32.0-SNAPSHOT 17 | 18 | 19 | 20 | 21 | 22 | org.apache.maven.plugins 23 | maven-compiler-plugin 24 | 3.14.0 25 | 26 | 27 | -parameters 28 | 29 | 30 | 31 | 32 | org.codehaus.mojo 33 | exec-maven-plugin 34 | 3.5.0 35 | 36 | false 37 | 38 | 39 | 40 | org.graalvm.buildtools 41 | native-maven-plugin 42 | 0.11.1 43 | true 44 | 45 | 46 | 47 | build 48 | test 49 | 50 | package 51 | 52 | 53 | 54 | 55 | -Ob 56 | --no-fallback 57 | --verbose 58 | 59 | com.google.genai.examples.GenerateContent 60 | genai-example-app 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | com.google.genai 69 | google-genai 70 | ${google-genai.version} 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/CountTokensResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Local tokenizer count tokens result. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = CountTokensResult.Builder.class) 32 | public abstract class CountTokensResult extends JsonSerializable { 33 | /** The total number of tokens. */ 34 | @JsonProperty("totalTokens") 35 | public abstract Optional totalTokens(); 36 | 37 | /** Instantiates a builder for CountTokensResult. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_CountTokensResult.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for CountTokensResult. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `CountTokensResult.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_CountTokensResult.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for totalTokens. 57 | * 58 | *

totalTokens: The total number of tokens. 59 | */ 60 | @JsonProperty("totalTokens") 61 | public abstract Builder totalTokens(Integer totalTokens); 62 | 63 | @ExcludeFromGeneratedCoverageReport 64 | abstract Builder totalTokens(Optional totalTokens); 65 | 66 | /** Clears the value of totalTokens field. */ 67 | @ExcludeFromGeneratedCoverageReport 68 | @CanIgnoreReturnValue 69 | public Builder clearTotalTokens() { 70 | return totalTokens(Optional.empty()); 71 | } 72 | 73 | public abstract CountTokensResult build(); 74 | } 75 | 76 | /** Deserializes a JSON string to a CountTokensResult object. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | public static CountTokensResult fromJson(String jsonString) { 79 | return JsonSerializable.fromJsonString(jsonString, CountTokensResult.class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/PrebuiltVoiceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** The configuration for the prebuilt speaker to use. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = PrebuiltVoiceConfig.Builder.class) 32 | public abstract class PrebuiltVoiceConfig extends JsonSerializable { 33 | /** The name of the preset voice to use. */ 34 | @JsonProperty("voiceName") 35 | public abstract Optional voiceName(); 36 | 37 | /** Instantiates a builder for PrebuiltVoiceConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_PrebuiltVoiceConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for PrebuiltVoiceConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `PrebuiltVoiceConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_PrebuiltVoiceConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for voiceName. 57 | * 58 | *

voiceName: The name of the preset voice to use. 59 | */ 60 | @JsonProperty("voiceName") 61 | public abstract Builder voiceName(String voiceName); 62 | 63 | @ExcludeFromGeneratedCoverageReport 64 | abstract Builder voiceName(Optional voiceName); 65 | 66 | /** Clears the value of voiceName field. */ 67 | @ExcludeFromGeneratedCoverageReport 68 | @CanIgnoreReturnValue 69 | public Builder clearVoiceName() { 70 | return voiceName(Optional.empty()); 71 | } 72 | 73 | public abstract PrebuiltVoiceConfig build(); 74 | } 75 | 76 | /** Deserializes a JSON string to a PrebuiltVoiceConfig object. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | public static PrebuiltVoiceConfig fromJson(String jsonString) { 79 | return JsonSerializable.fromJsonString(jsonString, PrebuiltVoiceConfig.class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/EmbedContent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Usage: 19 | * 20 | *

1a. If you are using Vertex AI, setup ADC to get credentials: 21 | * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp 22 | * 23 | *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: 24 | * 25 | *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT 26 | * 27 | *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION 28 | * 29 | *

export GOOGLE_GENAI_USE_VERTEXAI=true 30 | * 31 | *

1b. If you are using Gemini Developer API, set an API key environment variable. You can find a 32 | * list of available API keys here: https://aistudio.google.com/app/apikey 33 | * 34 | *

export GOOGLE_API_KEY=YOUR_API_KEY 35 | * 36 | *

2. Compile the java package and run the sample code. 37 | * 38 | *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.EmbedContent" 39 | * -Dexec.args="YOUR_MODEL_ID" 40 | */ 41 | package com.google.genai.examples; 42 | 43 | import com.google.genai.Client; 44 | import com.google.genai.types.EmbedContentResponse; 45 | 46 | /** An example of using the Unified Gen AI Java SDK to embed content. */ 47 | public final class EmbedContent { 48 | public static void main(String[] args) { 49 | final String modelId; 50 | if (args.length != 0) { 51 | modelId = args[0]; 52 | } else { 53 | modelId = Constants.EMBEDDING_MODEL_NAME; 54 | } 55 | 56 | // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API 57 | // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the 58 | // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting 59 | // `GOOGLE_GENAI_USE_VERTEXAI` to "true". 60 | // 61 | // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will 62 | // get a `UnsupportedOperationException` if you try to use a service that is not available in 63 | // the backend you are using. 64 | Client client = new Client(); 65 | 66 | if (client.vertexAI()) { 67 | System.out.println("Using Vertex AI"); 68 | } else { 69 | System.out.println("Using Gemini Developer API"); 70 | } 71 | 72 | EmbedContentResponse response = 73 | client.models.embedContent(modelId, "why is the sky blue?", null); 74 | 75 | System.out.println("Embedding response: " + response); 76 | } 77 | 78 | private EmbedContent() {} 79 | } 80 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/CountTokens.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Usage: 19 | * 20 | *

1a. If you are using Vertex AI, setup ADC to get credentials: 21 | * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp 22 | * 23 | *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: 24 | * 25 | *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT 26 | * 27 | *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION 28 | * 29 | *

export GOOGLE_GENAI_USE_VERTEXAI=true 30 | * 31 | *

1b. If you are using Gemini Developer API, set an API key environment variable. You can find a 32 | * list of available API keys here: https://aistudio.google.com/app/apikey 33 | * 34 | *

export GOOGLE_API_KEY=YOUR_API_KEY 35 | * 36 | *

2. Compile the java package and run the sample code. 37 | * 38 | *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.CountTokens" 39 | * -Dexec.args="YOUR_MODEL_ID" 40 | */ 41 | package com.google.genai.examples; 42 | 43 | import com.google.genai.Client; 44 | import com.google.genai.types.CountTokensResponse; 45 | 46 | /** An example of using the Unified Gen AI Java SDK to count tokens for simple text input. */ 47 | public final class CountTokens { 48 | public static void main(String[] args) { 49 | final String modelId; 50 | if (args.length != 0) { 51 | modelId = args[0]; 52 | } else { 53 | modelId = Constants.GEMINI_MODEL_NAME; 54 | } 55 | 56 | // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API 57 | // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the 58 | // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting 59 | // `GOOGLE_GENAI_USE_VERTEXAI` to "true". 60 | // 61 | // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will 62 | // get a `UnsupportedOperationException` if you try to use a service that is not available in 63 | // the backend you are using. 64 | Client client = new Client(); 65 | 66 | if (client.vertexAI()) { 67 | System.out.println("Using Vertex AI"); 68 | } else { 69 | System.out.println("Using Gemini Developer API"); 70 | } 71 | 72 | CountTokensResponse response = 73 | client.models.countTokens(modelId, "What is your name?", null); 74 | 75 | System.out.println("Count tokens response: " + response); 76 | } 77 | 78 | private CountTokens() {} 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/LiveServerSetupComplete.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Sent in response to a `LiveGenerateContentSetup` message from the client. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = LiveServerSetupComplete.Builder.class) 32 | public abstract class LiveServerSetupComplete extends JsonSerializable { 33 | /** The session id of the live session. */ 34 | @JsonProperty("sessionId") 35 | public abstract Optional sessionId(); 36 | 37 | /** Instantiates a builder for LiveServerSetupComplete. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_LiveServerSetupComplete.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for LiveServerSetupComplete. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `LiveServerSetupComplete.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_LiveServerSetupComplete.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for sessionId. 57 | * 58 | *

sessionId: The session id of the live session. 59 | */ 60 | @JsonProperty("sessionId") 61 | public abstract Builder sessionId(String sessionId); 62 | 63 | @ExcludeFromGeneratedCoverageReport 64 | abstract Builder sessionId(Optional sessionId); 65 | 66 | /** Clears the value of sessionId field. */ 67 | @ExcludeFromGeneratedCoverageReport 68 | @CanIgnoreReturnValue 69 | public Builder clearSessionId() { 70 | return sessionId(Optional.empty()); 71 | } 72 | 73 | public abstract LiveServerSetupComplete build(); 74 | } 75 | 76 | /** Deserializes a JSON string to a LiveServerSetupComplete object. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | public static LiveServerSetupComplete fromJson(String jsonString) { 79 | return JsonSerializable.fromJsonString(jsonString, LiveServerSetupComplete.class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/GenerateContentWithHttpOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Usage: 19 | * 20 | *

1a. If you are using Vertex AI, setup ADC to get credentials: 21 | * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp 22 | * 23 | *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: 24 | * 25 | *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT 26 | * 27 | *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION 28 | * 29 | *

export GOOGLE_GENAI_USE_VERTEXAI=true 30 | * 31 | *

1b. If you are using Gemini Developer API, set an API key environment variable. You can find a 32 | * list of available API keys here: https://aistudio.google.com/app/apikey 33 | * 34 | *

export GOOGLE_API_KEY=YOUR_API_KEY 35 | * 36 | *

2. Compile the java package and run the sample code. 37 | * 38 | *

mvn clean compile 39 | * 40 | *

mvn exec:java -Dexec.mainClass="com.google.genai.examples.GenerateContentWithHttpOptions" 41 | * -Dexec.args="YOUR_MODEL_ID" 42 | */ 43 | package com.google.genai.examples; 44 | 45 | import com.google.genai.Client; 46 | import com.google.genai.types.GenerateContentResponse; 47 | import com.google.genai.types.HttpOptions; 48 | import com.google.genai.types.HttpRetryOptions; 49 | 50 | /** An example of setting http options in a GenerateContent request. */ 51 | public final class GenerateContentWithHttpOptions { 52 | public static void main(String[] args) { 53 | final String modelId; 54 | if (args.length != 0) { 55 | modelId = args[0]; 56 | } else { 57 | modelId = Constants.GEMINI_MODEL_NAME; 58 | } 59 | 60 | // Set the client level http options when creating the client. All the API requests will share 61 | // the same http options. 62 | HttpOptions httpOptions = 63 | HttpOptions.builder() 64 | .apiVersion("v1") 65 | .timeout(10000) 66 | .retryOptions(HttpRetryOptions.builder().attempts(3).httpStatusCodes(408, 429, 504)) 67 | .build(); 68 | 69 | Client client = Client.builder().httpOptions(httpOptions).build(); 70 | 71 | if (client.vertexAI()) { 72 | System.out.println("Using Vertex AI"); 73 | } else { 74 | System.out.println("Using Gemini Developer API"); 75 | } 76 | 77 | GenerateContentResponse response = 78 | client.models.generateContent(modelId, "Tell me the history of LLM in 100 words", null); 79 | 80 | System.out.println("Response: " + response.text()); 81 | } 82 | 83 | private GenerateContentWithHttpOptions() {} 84 | } 85 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/OperationsTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import static org.junit.jupiter.api.Assertions.assertNotNull; 20 | import static org.junit.jupiter.api.Assertions.assertTrue; 21 | 22 | import com.google.genai.types.GenerateVideosOperation; 23 | import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; 24 | import org.junit.jupiter.api.extension.ExtendWith; 25 | import org.junit.jupiter.params.ParameterizedTest; 26 | import org.junit.jupiter.params.provider.ValueSource; 27 | 28 | @EnabledIfEnvironmentVariable( 29 | named = "GOOGLE_GENAI_REPLAYS_DIRECTORY", 30 | matches = ".*genai/replays.*") 31 | @ExtendWith(EnvironmentVariablesMockingExtension.class) 32 | public class OperationsTest { 33 | 34 | @ParameterizedTest 35 | @ValueSource(booleans = {false, true}) 36 | public void testGetVideosOperation(boolean vertexAI) throws Exception { 37 | // Arrange 38 | String suffix = vertexAI ? "vertex" : "mldev"; 39 | Client client = 40 | TestUtils.createClient( 41 | vertexAI, 42 | "tests/models/generate_videos/test_create_operation_to_poll." + suffix + ".json"); 43 | 44 | String operationName = 45 | vertexAI 46 | ? "projects//locations//publishers/google/models/veo-3.1-generate-preview/operations/9d2fc0b5-5bdf-4b5f-9a41-82970515e20b" 47 | : "models/veo-3.1-generate-preview/operations/vz341u0pmdlc"; 48 | 49 | // Act 50 | GenerateVideosOperation generateVideosOperation = 51 | client.operations.getVideosOperation( 52 | GenerateVideosOperation.builder().name(operationName).build(), null); 53 | 54 | // GenerateVideosOperation.done() is empty if the operation is not done. 55 | while (!generateVideosOperation.done().filter(Boolean::booleanValue).isPresent()) { 56 | try { 57 | if (!client.clientMode().equals("replay")) { 58 | Thread.sleep(10000); // Sleep for 10 seconds. 59 | System.out.println("Waiting for operation to complete..."); 60 | } 61 | generateVideosOperation = 62 | client.operations.getVideosOperation(generateVideosOperation, null); 63 | } catch (InterruptedException e) { 64 | System.out.println("Thread was interrupted while sleeping."); 65 | Thread.currentThread().interrupt(); 66 | } 67 | } 68 | 69 | // Arrange 70 | assertTrue(generateVideosOperation.done().get()); 71 | assertNotNull( 72 | generateVideosOperation.response().get().generatedVideos().get().get(0).video().get()); 73 | } 74 | } -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GeneratedVideo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** A generated video. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GeneratedVideo.Builder.class) 32 | public abstract class GeneratedVideo extends JsonSerializable { 33 | /** The output video */ 34 | @JsonProperty("video") 35 | public abstract Optional

video: The output video 59 | */ 60 | @JsonProperty("video") 61 | public abstract Builder video(Video video); 62 | 63 | /** 64 | * Setter for video builder. 65 | * 66 | *

video: The output video 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder video(Video.Builder videoBuilder) { 70 | return video(videoBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder video(Optional

1a. If you are using Vertex AI, setup ADC to get credentials: 21 | * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp 22 | * 23 | *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: 24 | * 25 | *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT 26 | * 27 | *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION 28 | * 29 | *

export GOOGLE_GENAI_USE_VERTEXAI=true 30 | * 31 | *

1b. If you are using Gemini Developer API, set an API key environment variable. You can find a 32 | * list of available API keys here: https://aistudio.google.com/app/apikey 33 | * 34 | *

export GOOGLE_API_KEY=YOUR_API_KEY 35 | * 36 | *

2. Compile the java package and run the sample code. 37 | * 38 | *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.ComputeTokens" 39 | * -Dexec.args="YOUR_MODEL_ID" 40 | */ 41 | package com.google.genai.examples; 42 | 43 | import com.google.genai.Client; 44 | import com.google.genai.types.ComputeTokensResponse; 45 | 46 | /** An example of using the Unified Gen AI Java SDK to compute tokens for simple text input. */ 47 | public final class ComputeTokens { 48 | public static void main(String[] args) { 49 | final String modelId; 50 | if (args.length != 0) { 51 | modelId = args[0]; 52 | } else { 53 | modelId = Constants.GEMINI_MODEL_NAME; 54 | } 55 | 56 | // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API 57 | // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the 58 | // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting 59 | // `GOOGLE_GENAI_USE_VERTEXAI` to "true". 60 | // 61 | // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will 62 | // get a `UnsupportedOperationException` if you try to use a service that is not available in 63 | // the backend you are using. 64 | Client client = new Client(); 65 | 66 | if (client.vertexAI()) { 67 | System.out.println("Using Vertex AI"); 68 | } else { 69 | System.out.println("Gemini Developer API is not supported for this example."); 70 | System.exit(0); 71 | } 72 | 73 | ComputeTokensResponse response = 74 | client.models.computeTokens(modelId, "What is your name?", null); 75 | 76 | System.out.println("Compute tokens response: " + response); 77 | } 78 | 79 | private ComputeTokens() {} 80 | } 81 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/GenerateContentWithClientOptions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Usage: 19 | * 20 | *

1a. If you are using Vertex AI, setup ADC to get credentials: 21 | * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp 22 | * 23 | *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: 24 | * 25 | *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT 26 | * 27 | *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION 28 | * 29 | *

export GOOGLE_GENAI_USE_VERTEXAI=true 30 | * 31 | *

1b. If you are using Gemini Developer API, set an API key environment variable. You can find a 32 | * list of available API keys here: https://aistudio.google.com/app/apikey 33 | * 34 | *

export GOOGLE_API_KEY=YOUR_API_KEY 35 | * 36 | *

2. Compile the java package and run the sample code. 37 | * 38 | *

mvn clean compile 39 | * 40 | *

mvn exec:java -Dexec.mainClass="com.google.genai.examples.GenerateContentWithClientOptions" 41 | * -Dexec.args="YOUR_MODEL_ID" 42 | */ 43 | package com.google.genai.examples; 44 | 45 | import com.google.genai.Client; 46 | import com.google.genai.types.ClientOptions; 47 | import com.google.genai.types.GenerateContentResponse; 48 | import com.google.genai.types.ProxyOptions; 49 | import com.google.genai.types.ProxyType; 50 | 51 | /** An example of setting client options in a GenerateContent request. */ 52 | public final class GenerateContentWithClientOptions { 53 | public static void main(String[] args) { 54 | final String modelId; 55 | if (args.length != 0) { 56 | modelId = args[0]; 57 | } else { 58 | modelId = Constants.GEMINI_MODEL_NAME; 59 | } 60 | 61 | // Set the client options when creating the client. This applies to all requests made through 62 | // this client. 63 | ClientOptions clientOptions = 64 | ClientOptions.builder() 65 | .proxyOptions(ProxyOptions.builder().type(ProxyType.Known.DIRECT)) 66 | .maxConnections(10) 67 | .maxConnectionsPerHost(5) 68 | .build(); 69 | 70 | Client client = Client.builder().clientOptions(clientOptions).build(); 71 | 72 | if (client.vertexAI()) { 73 | System.out.println("Using Vertex AI"); 74 | } else { 75 | System.out.println("Using Gemini Developer API"); 76 | } 77 | 78 | GenerateContentResponse response = 79 | client.models.generateContent(modelId, "Tell me the history of LLM in 100 words", null); 80 | 81 | System.out.println("Response: " + response.text()); 82 | } 83 | 84 | private GenerateContentWithClientOptions() {} 85 | } 86 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/Constants.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai.examples; 18 | 19 | /** A final class to hold constants shared across all examples. */ 20 | public final class Constants { 21 | 22 | private Constants() {} 23 | 24 | /** The name of the generative model to be used in the examples. */ 25 | public static final String GEMINI_MODEL_NAME = "gemini-2.5-flash"; 26 | 27 | /** The name of the gemini 3 model to be used in the examples. */ 28 | public static final String GEMINI_3_MODEL_NAME = "gemini-3-pro-preview"; 29 | 30 | /** The name of the live model to be used in the examples. */ 31 | public static final String GEMINI_LIVE_MODEL_NAME = "gemini-live-2.5-flash"; 32 | 33 | /** The name of the preview live model to be used in the examples. */ 34 | public static final String GEMINI_LIVE_MODEL_NAME_PREVIEW = "gemini-2.5-flash-native-audio-preview-09-2025"; 35 | 36 | /** The name of the image generation model to be used in the examples. */ 37 | public static final String GEMINI_IMAGE_GENERATION_MODEL_NAME = "gemini-2.5-flash-image"; 38 | 39 | /** The name of the Imagen generate model to be used in the examples. */ 40 | public static final String IMAGEN_GENERATE_MODEL_NAME = "imagen-4.0-generate-001"; 41 | 42 | /** The name of the Imagen model to be used for image editing in the examples. */ 43 | public static final String IMAGEN_CAPABILITY_MODEL_NAME = "imagen-3.0-capability-001"; 44 | 45 | /** The name of the Imagen ingredients model to be used in the examples. */ 46 | public static final String IMAGEN_INGREDIENTS_MODEL_NAME = "imagen-4.0-ingredients-preview"; 47 | 48 | /** The name of the Imagen product recontext model to be used in the examples. */ 49 | public static final String IMAGEN_RECONTEXT_MODEL_NAME = "imagen-product-recontext-preview-06-30"; 50 | 51 | /** The name of the Virtual try-on model to be used in the examples. */ 52 | public static final String VIRTUAL_TRY_ON_MODEL_NAME = "virtual-try-on-preview-08-04"; 53 | 54 | /** The name of the segment image model to be used in the examples. */ 55 | public static final String SEGMENT_IMAGE_MODEL_NAME = "image-segmentation-001"; 56 | 57 | /** The name of the Veo model to be used in the examples. */ 58 | public static final String VEO_MODEL_NAME = "veo-3.1-generate-preview"; 59 | 60 | /** The name of the embedding model to be used in the examples. */ 61 | public static final String EMBEDDING_MODEL_NAME = "text-embedding-004"; 62 | 63 | /** The file path to be used in the files operations examples. */ 64 | public static final String UPLOAD_FILE_PATH = "./resources/test.txt"; 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/StyleReferenceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Configuration for a Style reference image. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = StyleReferenceConfig.Builder.class) 32 | public abstract class StyleReferenceConfig extends JsonSerializable { 33 | /** A text description of the style to use for the generated image. */ 34 | @JsonProperty("styleDescription") 35 | public abstract Optional styleDescription(); 36 | 37 | /** Instantiates a builder for StyleReferenceConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_StyleReferenceConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for StyleReferenceConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `StyleReferenceConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_StyleReferenceConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for styleDescription. 57 | * 58 | *

styleDescription: A text description of the style to use for the generated image. 59 | */ 60 | @JsonProperty("styleDescription") 61 | public abstract Builder styleDescription(String styleDescription); 62 | 63 | @ExcludeFromGeneratedCoverageReport 64 | abstract Builder styleDescription(Optional styleDescription); 65 | 66 | /** Clears the value of styleDescription field. */ 67 | @ExcludeFromGeneratedCoverageReport 68 | @CanIgnoreReturnValue 69 | public Builder clearStyleDescription() { 70 | return styleDescription(Optional.empty()); 71 | } 72 | 73 | public abstract StyleReferenceConfig build(); 74 | } 75 | 76 | /** Deserializes a JSON string to a StyleReferenceConfig object. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | public static StyleReferenceConfig fromJson(String jsonString) { 79 | return JsonSerializable.fromJsonString(jsonString, StyleReferenceConfig.class); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/Mode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonValue; 23 | import com.google.common.base.Ascii; 24 | import java.util.Objects; 25 | 26 | /** The mode of the predictor to be used in dynamic retrieval. */ 27 | public class Mode { 28 | 29 | /** Enum representing the known values for Mode. */ 30 | public enum Known { 31 | /** Always trigger retrieval. */ 32 | MODE_UNSPECIFIED, 33 | 34 | /** Run retrieval only when system decides it is necessary. */ 35 | MODE_DYNAMIC 36 | } 37 | 38 | private Known modeEnum; 39 | private final String value; 40 | 41 | @JsonCreator 42 | public Mode(String value) { 43 | this.value = value; 44 | for (Known modeEnum : Known.values()) { 45 | if (Ascii.equalsIgnoreCase(modeEnum.toString(), value)) { 46 | this.modeEnum = modeEnum; 47 | break; 48 | } 49 | } 50 | if (this.modeEnum == null) { 51 | this.modeEnum = Known.MODE_UNSPECIFIED; 52 | } 53 | } 54 | 55 | public Mode(Known knownValue) { 56 | this.modeEnum = knownValue; 57 | this.value = knownValue.toString(); 58 | } 59 | 60 | @ExcludeFromGeneratedCoverageReport 61 | @Override 62 | @JsonValue 63 | public String toString() { 64 | return this.value; 65 | } 66 | 67 | @ExcludeFromGeneratedCoverageReport 68 | @SuppressWarnings("PatternMatchingInstanceof") 69 | @Override 70 | public boolean equals(Object o) { 71 | if (this == o) { 72 | return true; 73 | } 74 | if (o == null) { 75 | return false; 76 | } 77 | 78 | if (!(o instanceof Mode)) { 79 | return false; 80 | } 81 | 82 | Mode other = (Mode) o; 83 | 84 | if (this.modeEnum != Known.MODE_UNSPECIFIED && other.modeEnum != Known.MODE_UNSPECIFIED) { 85 | return this.modeEnum == other.modeEnum; 86 | } else if (this.modeEnum == Known.MODE_UNSPECIFIED 87 | && other.modeEnum == Known.MODE_UNSPECIFIED) { 88 | return this.value.equals(other.value); 89 | } 90 | return false; 91 | } 92 | 93 | @ExcludeFromGeneratedCoverageReport 94 | @Override 95 | public int hashCode() { 96 | if (this.modeEnum != Known.MODE_UNSPECIFIED) { 97 | return this.modeEnum.hashCode(); 98 | } else { 99 | return Objects.hashCode(this.value); 100 | } 101 | } 102 | 103 | @ExcludeFromGeneratedCoverageReport 104 | public Known knownEnum() { 105 | return this.modeEnum; 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ListModelsParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.api.core.InternalApi; 25 | import com.google.auto.value.AutoValue; 26 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 27 | import com.google.genai.JsonSerializable; 28 | import java.util.Optional; 29 | 30 | /** None */ 31 | @AutoValue 32 | @InternalApi 33 | @JsonDeserialize(builder = ListModelsParameters.Builder.class) 34 | public abstract class ListModelsParameters extends JsonSerializable { 35 | /** */ 36 | @JsonProperty("config") 37 | public abstract Optional config(); 38 | 39 | /** Instantiates a builder for ListModelsParameters. */ 40 | @ExcludeFromGeneratedCoverageReport 41 | public static Builder builder() { 42 | return new AutoValue_ListModelsParameters.Builder(); 43 | } 44 | 45 | /** Creates a builder with the same values as this instance. */ 46 | public abstract Builder toBuilder(); 47 | 48 | /** Builder for ListModelsParameters. */ 49 | @AutoValue.Builder 50 | public abstract static class Builder { 51 | /** For internal usage. Please use `ListModelsParameters.builder()` for instantiation. */ 52 | @JsonCreator 53 | private static Builder create() { 54 | return new AutoValue_ListModelsParameters.Builder(); 55 | } 56 | 57 | /** 58 | * Setter for config. 59 | * 60 | *

config: 61 | */ 62 | @JsonProperty("config") 63 | public abstract Builder config(ListModelsConfig config); 64 | 65 | /** 66 | * Setter for config builder. 67 | * 68 | *

config: 69 | */ 70 | @CanIgnoreReturnValue 71 | public Builder config(ListModelsConfig.Builder configBuilder) { 72 | return config(configBuilder.build()); 73 | } 74 | 75 | @ExcludeFromGeneratedCoverageReport 76 | abstract Builder config(Optional config); 77 | 78 | /** Clears the value of config field. */ 79 | @ExcludeFromGeneratedCoverageReport 80 | @CanIgnoreReturnValue 81 | public Builder clearConfig() { 82 | return config(Optional.empty()); 83 | } 84 | 85 | public abstract ListModelsParameters build(); 86 | } 87 | 88 | /** Deserializes a JSON string to a ListModelsParameters object. */ 89 | @ExcludeFromGeneratedCoverageReport 90 | public static ListModelsParameters fromJson(String jsonString) { 91 | return JsonSerializable.fromJsonString(jsonString, ListModelsParameters.class); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/NullValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonValue; 23 | import com.google.common.base.Ascii; 24 | import java.util.Objects; 25 | 26 | /** Optional. Represents a null value. */ 27 | public class NullValue { 28 | 29 | /** Enum representing the known values for NullValue. */ 30 | public enum Known { 31 | NULL_VALUE, 32 | 33 | NULL_VALUE_UNSPECIFIED 34 | } 35 | 36 | private Known nullValueEnum; 37 | private final String value; 38 | 39 | @JsonCreator 40 | public NullValue(String value) { 41 | this.value = value; 42 | for (Known nullValueEnum : Known.values()) { 43 | if (Ascii.equalsIgnoreCase(nullValueEnum.toString(), value)) { 44 | this.nullValueEnum = nullValueEnum; 45 | break; 46 | } 47 | } 48 | if (this.nullValueEnum == null) { 49 | this.nullValueEnum = Known.NULL_VALUE_UNSPECIFIED; 50 | } 51 | } 52 | 53 | public NullValue(Known knownValue) { 54 | this.nullValueEnum = knownValue; 55 | this.value = knownValue.toString(); 56 | } 57 | 58 | @ExcludeFromGeneratedCoverageReport 59 | @Override 60 | @JsonValue 61 | public String toString() { 62 | return this.value; 63 | } 64 | 65 | @ExcludeFromGeneratedCoverageReport 66 | @SuppressWarnings("PatternMatchingInstanceof") 67 | @Override 68 | public boolean equals(Object o) { 69 | if (this == o) { 70 | return true; 71 | } 72 | if (o == null) { 73 | return false; 74 | } 75 | 76 | if (!(o instanceof NullValue)) { 77 | return false; 78 | } 79 | 80 | NullValue other = (NullValue) o; 81 | 82 | if (this.nullValueEnum != Known.NULL_VALUE_UNSPECIFIED 83 | && other.nullValueEnum != Known.NULL_VALUE_UNSPECIFIED) { 84 | return this.nullValueEnum == other.nullValueEnum; 85 | } else if (this.nullValueEnum == Known.NULL_VALUE_UNSPECIFIED 86 | && other.nullValueEnum == Known.NULL_VALUE_UNSPECIFIED) { 87 | return this.value.equals(other.value); 88 | } 89 | return false; 90 | } 91 | 92 | @ExcludeFromGeneratedCoverageReport 93 | @Override 94 | public int hashCode() { 95 | if (this.nullValueEnum != Known.NULL_VALUE_UNSPECIFIED) { 96 | return this.nullValueEnum.hashCode(); 97 | } else { 98 | return Objects.hashCode(this.value); 99 | } 100 | } 101 | 102 | @ExcludeFromGeneratedCoverageReport 103 | public Known knownEnum() { 104 | return this.nullValueEnum; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ScribbleImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** An image mask representing a brush scribble. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = ScribbleImage.Builder.class) 32 | public abstract class ScribbleImage extends JsonSerializable { 33 | /** The brush scribble to guide segmentation. Valid for the interactive mode. */ 34 | @JsonProperty("image") 35 | public abstract Optional image(); 36 | 37 | /** Instantiates a builder for ScribbleImage. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_ScribbleImage.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for ScribbleImage. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `ScribbleImage.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_ScribbleImage.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for image. 57 | * 58 | *

image: The brush scribble to guide segmentation. Valid for the interactive mode. 59 | */ 60 | @JsonProperty("image") 61 | public abstract Builder image(Image image); 62 | 63 | /** 64 | * Setter for image builder. 65 | * 66 | *

image: The brush scribble to guide segmentation. Valid for the interactive mode. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder image(Image.Builder imageBuilder) { 70 | return image(imageBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder image(Optional image); 75 | 76 | /** Clears the value of image field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearImage() { 80 | return image(Optional.empty()); 81 | } 82 | 83 | public abstract ScribbleImage build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a ScribbleImage object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static ScribbleImage fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, ScribbleImage.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/EmbedContentMetadata.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Request-level metadata for the Vertex Embed Content API. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = EmbedContentMetadata.Builder.class) 32 | public abstract class EmbedContentMetadata extends JsonSerializable { 33 | /** Vertex API only. The total number of billable characters included in the request. */ 34 | @JsonProperty("billableCharacterCount") 35 | public abstract Optional billableCharacterCount(); 36 | 37 | /** Instantiates a builder for EmbedContentMetadata. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_EmbedContentMetadata.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for EmbedContentMetadata. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `EmbedContentMetadata.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_EmbedContentMetadata.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for billableCharacterCount. 57 | * 58 | *

billableCharacterCount: Vertex API only. The total number of billable characters included 59 | * in the request. 60 | */ 61 | @JsonProperty("billableCharacterCount") 62 | public abstract Builder billableCharacterCount(Integer billableCharacterCount); 63 | 64 | @ExcludeFromGeneratedCoverageReport 65 | abstract Builder billableCharacterCount(Optional billableCharacterCount); 66 | 67 | /** Clears the value of billableCharacterCount field. */ 68 | @ExcludeFromGeneratedCoverageReport 69 | @CanIgnoreReturnValue 70 | public Builder clearBillableCharacterCount() { 71 | return billableCharacterCount(Optional.empty()); 72 | } 73 | 74 | public abstract EmbedContentMetadata build(); 75 | } 76 | 77 | /** Deserializes a JSON string to a EmbedContentMetadata object. */ 78 | @ExcludeFromGeneratedCoverageReport 79 | public static EmbedContentMetadata fromJson(String jsonString) { 80 | return JsonSerializable.fromJsonString(jsonString, EmbedContentMetadata.class); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/com/google/genai/EnvironmentVariablesMockingExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.google.genai; 18 | 19 | import com.google.common.collect.ImmutableMap; 20 | import org.junit.jupiter.api.extension.AfterEachCallback; 21 | import org.junit.jupiter.api.extension.BeforeEachCallback; 22 | import org.junit.jupiter.api.extension.ExtensionContext; 23 | import org.junit.jupiter.api.extension.ExtensionContext.Namespace; 24 | import org.junit.jupiter.api.extension.ExtensionContext.Store; 25 | import org.junit.jupiter.api.extension.ParameterContext; 26 | import org.junit.jupiter.api.extension.ParameterResolver; 27 | import org.mockito.MockedStatic; 28 | import org.mockito.Mockito; 29 | 30 | /** 31 | * Extension that mocks the default environment variables in the ApiClient class. 32 | * 33 | *

This extension is used to mock the default environment variables in the ApiClient class in 34 | * order to avoid reading the actual environment variables in replay mode. 35 | */ 36 | public class EnvironmentVariablesMockingExtension 37 | implements BeforeEachCallback, AfterEachCallback, ParameterResolver { 38 | 39 | private static final Namespace NAMESPACE = 40 | Namespace.create(EnvironmentVariablesMockingExtension.class); 41 | private static final String MOCKED_STATIC_KEY = "mockedStaticApiClient"; 42 | 43 | @Override 44 | public void beforeEach(ExtensionContext context) throws Exception { 45 | String clientMode = System.getenv("GOOGLE_GENAI_CLIENT_MODE"); 46 | if (clientMode != null && clientMode.equals("api")) { 47 | return; 48 | } 49 | 50 | MockedStatic mockedStatic = 51 | Mockito.mockStatic(ApiClient.class, Mockito.CALLS_REAL_METHODS); 52 | 53 | mockedStatic.when(ApiClient::defaultEnvironmentVariables).thenReturn(ImmutableMap.of()); 54 | 55 | getStore(context).put(MOCKED_STATIC_KEY, mockedStatic); 56 | } 57 | 58 | @Override 59 | public void afterEach(ExtensionContext context) throws Exception { 60 | MockedStatic mockedStatic = getStore(context).remove(MOCKED_STATIC_KEY, MockedStatic.class); 61 | if (mockedStatic != null) { 62 | mockedStatic.close(); 63 | } 64 | } 65 | 66 | @Override 67 | public boolean supportsParameter( 68 | ParameterContext parameterContext, ExtensionContext extensionContext) { 69 | return parameterContext.getParameter().getType() == MockedStatic.class; 70 | } 71 | 72 | @Override 73 | public Object resolveParameter( 74 | ParameterContext parameterContext, ExtensionContext extensionContext) { 75 | return getStore(extensionContext).get(MOCKED_STATIC_KEY, MockedStatic.class); 76 | } 77 | 78 | private Store getStore(ExtensionContext context) { 79 | return context.getStore(Namespace.create(context.getRequiredTestMethod())); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /examples/src/main/java/com/google/genai/examples/EmbedContentAsync.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Usage: 19 | * 20 | *

1a. If you are using Vertex AI, setup ADC to get credentials: 21 | * https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp 22 | * 23 | *

Then set Project, Location, and USE_VERTEXAI flag as environment variables: 24 | * 25 | *

export GOOGLE_CLOUD_PROJECT=YOUR_PROJECT 26 | * 27 | *

export GOOGLE_CLOUD_LOCATION=YOUR_LOCATION 28 | * 29 | *

export GOOGLE_GENAI_USE_VERTEXAI=true 30 | * 31 | *

1b. If you are using Gemini Developer API, set an API key environment variable. You can find a 32 | * list of available API keys here: https://aistudio.google.com/app/apikey 33 | * 34 | *

export GOOGLE_API_KEY=YOUR_API_KEY 35 | * 36 | *

2. Compile the java package and run the sample code. 37 | * 38 | *

mvn clean compile exec:java -Dexec.mainClass="com.google.genai.examples.EmbedContentAsync" 39 | * -Dexec.args="YOUR_MODEL_ID" 40 | */ 41 | package com.google.genai.examples; 42 | 43 | import com.google.genai.Client; 44 | import com.google.genai.types.EmbedContentResponse; 45 | import java.util.concurrent.CompletableFuture; 46 | 47 | /** An example of using the Unified Gen AI Java SDK to embed content asynchronously. */ 48 | public final class EmbedContentAsync { 49 | public static void main(String[] args) { 50 | final String modelId; 51 | if (args.length != 0) { 52 | modelId = args[0]; 53 | } else { 54 | modelId = Constants.EMBEDDING_MODEL_NAME; 55 | } 56 | 57 | // Instantiate the client. The client by default uses the Gemini Developer API. It gets the API 58 | // key from the environment variable `GOOGLE_API_KEY`. Vertex AI API can be used by setting the 59 | // environment variables `GOOGLE_CLOUD_LOCATION` and `GOOGLE_CLOUD_PROJECT`, as well as setting 60 | // `GOOGLE_GENAI_USE_VERTEXAI` to "true". 61 | // 62 | // Note: Some services are only available in a specific API backend (Gemini or Vertex), you will 63 | // get a `UnsupportedOperationException` if you try to use a service that is not available in 64 | // the backend you are using. 65 | Client client = new Client(); 66 | 67 | if (client.vertexAI()) { 68 | System.out.println("Using Vertex AI"); 69 | } else { 70 | System.out.println("Using Gemini Developer API"); 71 | } 72 | 73 | CompletableFuture responseFuture = 74 | client.async.models.embedContent(modelId, "Why is the sky blue?", null); 75 | 76 | responseFuture 77 | .thenAccept( 78 | response -> { 79 | System.out.println("Async embedding response: " + response); 80 | }) 81 | .join(); 82 | } 83 | 84 | private EmbedContentAsync() {} 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ProductImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** An image of the product. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = ProductImage.Builder.class) 32 | public abstract class ProductImage extends JsonSerializable { 33 | /** An image of the product to be recontextualized. */ 34 | @JsonProperty("productImage") 35 | public abstract Optional productImage(); 36 | 37 | /** Instantiates a builder for ProductImage. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_ProductImage.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for ProductImage. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `ProductImage.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_ProductImage.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for productImage. 57 | * 58 | *

productImage: An image of the product to be recontextualized. 59 | */ 60 | @JsonProperty("productImage") 61 | public abstract Builder productImage(Image productImage); 62 | 63 | /** 64 | * Setter for productImage builder. 65 | * 66 | *

productImage: An image of the product to be recontextualized. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder productImage(Image.Builder productImageBuilder) { 70 | return productImage(productImageBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder productImage(Optional productImage); 75 | 76 | /** Clears the value of productImage field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearProductImage() { 80 | return productImage(Optional.empty()); 81 | } 82 | 83 | public abstract ProductImage build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a ProductImage object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static ProductImage fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, ProductImage.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GetFileConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Used to override the default configuration. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GetFileConfig.Builder.class) 32 | public abstract class GetFileConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for GetFileConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_GetFileConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for GetFileConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `GetFileConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_GetFileConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract GetFileConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a GetFileConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static GetFileConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, GetFileConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ListBatchJobsParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.api.core.InternalApi; 25 | import com.google.auto.value.AutoValue; 26 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 27 | import com.google.genai.JsonSerializable; 28 | import java.util.Optional; 29 | 30 | /** Config for batches.list parameters. */ 31 | @AutoValue 32 | @InternalApi 33 | @JsonDeserialize(builder = ListBatchJobsParameters.Builder.class) 34 | public abstract class ListBatchJobsParameters extends JsonSerializable { 35 | /** */ 36 | @JsonProperty("config") 37 | public abstract Optional config(); 38 | 39 | /** Instantiates a builder for ListBatchJobsParameters. */ 40 | @ExcludeFromGeneratedCoverageReport 41 | public static Builder builder() { 42 | return new AutoValue_ListBatchJobsParameters.Builder(); 43 | } 44 | 45 | /** Creates a builder with the same values as this instance. */ 46 | public abstract Builder toBuilder(); 47 | 48 | /** Builder for ListBatchJobsParameters. */ 49 | @AutoValue.Builder 50 | public abstract static class Builder { 51 | /** For internal usage. Please use `ListBatchJobsParameters.builder()` for instantiation. */ 52 | @JsonCreator 53 | private static Builder create() { 54 | return new AutoValue_ListBatchJobsParameters.Builder(); 55 | } 56 | 57 | /** 58 | * Setter for config. 59 | * 60 | *

config: 61 | */ 62 | @JsonProperty("config") 63 | public abstract Builder config(ListBatchJobsConfig config); 64 | 65 | /** 66 | * Setter for config builder. 67 | * 68 | *

config: 69 | */ 70 | @CanIgnoreReturnValue 71 | public Builder config(ListBatchJobsConfig.Builder configBuilder) { 72 | return config(configBuilder.build()); 73 | } 74 | 75 | @ExcludeFromGeneratedCoverageReport 76 | abstract Builder config(Optional config); 77 | 78 | /** Clears the value of config field. */ 79 | @ExcludeFromGeneratedCoverageReport 80 | @CanIgnoreReturnValue 81 | public Builder clearConfig() { 82 | return config(Optional.empty()); 83 | } 84 | 85 | public abstract ListBatchJobsParameters build(); 86 | } 87 | 88 | /** Deserializes a JSON string to a ListBatchJobsParameters object. */ 89 | @ExcludeFromGeneratedCoverageReport 90 | public static ListBatchJobsParameters fromJson(String jsonString) { 91 | return JsonSerializable.fromJsonString(jsonString, ListBatchJobsParameters.class); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/resources/META-INF/native-image/com.google.genai/google-genai/resource-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "resources":{ 3 | "includes":[{ 4 | "pattern":"\\QMETA-INF/services/com.google.auth.http.HttpTransportFactory\\E" 5 | }, { 6 | "pattern":"\\QMETA-INF/services/java.lang.System$LoggerFinder\\E" 7 | }, { 8 | "pattern":"\\QMETA-INF/services/java.net.spi.URLStreamHandlerProvider\\E" 9 | }, { 10 | "pattern":"\\QMETA-INF/services/java.nio.file.spi.FileTypeDetector\\E" 11 | }, { 12 | "pattern":"\\QMETA-INF/services/org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory\\E" 13 | }, { 14 | "pattern":"\\QMETA-INF/services/org.junit.platform.engine.TestEngine\\E" 15 | }, { 16 | "pattern":"\\QMETA-INF/services/org.junit.platform.launcher.LauncherDiscoveryListener\\E" 17 | }, { 18 | "pattern":"\\QMETA-INF/services/org.junit.platform.launcher.LauncherSessionListener\\E" 19 | }, { 20 | "pattern":"\\QMETA-INF/services/org.junit.platform.launcher.PostDiscoveryFilter\\E" 21 | }, { 22 | "pattern":"\\QMETA-INF/services/org.junit.platform.launcher.TestExecutionListener\\E" 23 | }, { 24 | "pattern":"\\Qbridge1.png\\E" 25 | }, { 26 | "pattern":"\\Qcheckerboard.png\\E" 27 | }, { 28 | "pattern":"\\Qcom/google/api/client/http/google-http-client.properties\\E" 29 | }, { 30 | "pattern":"\\Qcom/google/auth/oauth2/google-auth-library.properties\\E" 31 | }, { 32 | "pattern":"\\Qgoogle.png\\E" 33 | }, { 34 | "pattern":"\\Qjava/lang/reflect/AccessibleObject.class\\E" 35 | }, { 36 | "pattern":"\\Qjunit-platform.properties\\E" 37 | }, { 38 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.AnnotationEngine\\E" 39 | }, { 40 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.DoNotMockEnforcerWithType\\E" 41 | }, { 42 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.DoNotMockEnforcer\\E" 43 | }, { 44 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.InstantiatorProvider2\\E" 45 | }, { 46 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.MemberAccessor\\E" 47 | }, { 48 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.MockMaker\\E" 49 | }, { 50 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.MockResolver\\E" 51 | }, { 52 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.MockitoLogger\\E" 53 | }, { 54 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.PluginSwitch\\E" 55 | }, { 56 | "pattern":"\\Qmockito-extensions/org.mockito.plugins.StackTraceCleanerProvider\\E" 57 | }, { 58 | "pattern":"\\Qorg/mockito/internal/creation/bytebuddy/MockMethodAdvice$ForEquals.class\\E" 59 | }, { 60 | "pattern":"\\Qorg/mockito/internal/creation/bytebuddy/MockMethodAdvice$ForHashCode.class\\E" 61 | }, { 62 | "pattern":"\\Qorg/mockito/internal/creation/bytebuddy/MockMethodAdvice$ForStatic.class\\E" 63 | }, { 64 | "pattern":"\\Qorg/mockito/internal/creation/bytebuddy/MockMethodAdvice.class\\E" 65 | }, { 66 | "pattern":"\\Qorg/mockito/internal/creation/bytebuddy/inject/MockMethodDispatcher.raw\\E" 67 | }, { 68 | "pattern":"java.base:\\Qjava/lang/reflect/AccessibleObject.class\\E" 69 | }, { 70 | "pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt72b/nfkc.nrm\\E" 71 | }, { 72 | "pattern":"java.base:\\Qjdk/internal/icu/impl/data/icudt72b/uprops.icu\\E" 73 | }, { 74 | "pattern":"java.base:\\Qsun/net/idn/uidna.spp\\E" 75 | }]}, 76 | "bundles":[] 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/FileSource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonValue; 23 | import com.google.common.base.Ascii; 24 | import java.util.Objects; 25 | 26 | /** Source of the File. */ 27 | public class FileSource { 28 | 29 | /** Enum representing the known values for FileSource. */ 30 | public enum Known { 31 | SOURCE_UNSPECIFIED, 32 | 33 | UPLOADED, 34 | 35 | GENERATED, 36 | 37 | FILE_SOURCE_UNSPECIFIED 38 | } 39 | 40 | private Known fileSourceEnum; 41 | private final String value; 42 | 43 | @JsonCreator 44 | public FileSource(String value) { 45 | this.value = value; 46 | for (Known fileSourceEnum : Known.values()) { 47 | if (Ascii.equalsIgnoreCase(fileSourceEnum.toString(), value)) { 48 | this.fileSourceEnum = fileSourceEnum; 49 | break; 50 | } 51 | } 52 | if (this.fileSourceEnum == null) { 53 | this.fileSourceEnum = Known.FILE_SOURCE_UNSPECIFIED; 54 | } 55 | } 56 | 57 | public FileSource(Known knownValue) { 58 | this.fileSourceEnum = knownValue; 59 | this.value = knownValue.toString(); 60 | } 61 | 62 | @ExcludeFromGeneratedCoverageReport 63 | @Override 64 | @JsonValue 65 | public String toString() { 66 | return this.value; 67 | } 68 | 69 | @ExcludeFromGeneratedCoverageReport 70 | @SuppressWarnings("PatternMatchingInstanceof") 71 | @Override 72 | public boolean equals(Object o) { 73 | if (this == o) { 74 | return true; 75 | } 76 | if (o == null) { 77 | return false; 78 | } 79 | 80 | if (!(o instanceof FileSource)) { 81 | return false; 82 | } 83 | 84 | FileSource other = (FileSource) o; 85 | 86 | if (this.fileSourceEnum != Known.FILE_SOURCE_UNSPECIFIED 87 | && other.fileSourceEnum != Known.FILE_SOURCE_UNSPECIFIED) { 88 | return this.fileSourceEnum == other.fileSourceEnum; 89 | } else if (this.fileSourceEnum == Known.FILE_SOURCE_UNSPECIFIED 90 | && other.fileSourceEnum == Known.FILE_SOURCE_UNSPECIFIED) { 91 | return this.value.equals(other.value); 92 | } 93 | return false; 94 | } 95 | 96 | @ExcludeFromGeneratedCoverageReport 97 | @Override 98 | public int hashCode() { 99 | if (this.fileSourceEnum != Known.FILE_SOURCE_UNSPECIFIED) { 100 | return this.fileSourceEnum.hashCode(); 101 | } else { 102 | return Objects.hashCode(this.value); 103 | } 104 | } 105 | 106 | @ExcludeFromGeneratedCoverageReport 107 | public Known knownEnum() { 108 | return this.fileSourceEnum; 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GetModelConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Optional parameters for models.get method. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GetModelConfig.Builder.class) 32 | public abstract class GetModelConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for GetModelConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_GetModelConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for GetModelConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `GetModelConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_GetModelConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract GetModelConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a GetModelConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static GetModelConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, GetModelConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/StringList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Arrays; 28 | import java.util.List; 29 | import java.util.Optional; 30 | 31 | /** 32 | * User provided string values assigned to a single metadata key. This data type is not supported in 33 | * Vertex AI. 34 | */ 35 | @AutoValue 36 | @JsonDeserialize(builder = StringList.Builder.class) 37 | public abstract class StringList extends JsonSerializable { 38 | /** The string values of the metadata to store. */ 39 | @JsonProperty("values") 40 | public abstract Optional> values(); 41 | 42 | /** Instantiates a builder for StringList. */ 43 | @ExcludeFromGeneratedCoverageReport 44 | public static Builder builder() { 45 | return new AutoValue_StringList.Builder(); 46 | } 47 | 48 | /** Creates a builder with the same values as this instance. */ 49 | public abstract Builder toBuilder(); 50 | 51 | /** Builder for StringList. */ 52 | @AutoValue.Builder 53 | public abstract static class Builder { 54 | /** For internal usage. Please use `StringList.builder()` for instantiation. */ 55 | @JsonCreator 56 | private static Builder create() { 57 | return new AutoValue_StringList.Builder(); 58 | } 59 | 60 | /** 61 | * Setter for values. 62 | * 63 | *

values: The string values of the metadata to store. 64 | */ 65 | @JsonProperty("values") 66 | public abstract Builder values(List values); 67 | 68 | /** 69 | * Setter for values. 70 | * 71 | *

values: The string values of the metadata to store. 72 | */ 73 | @CanIgnoreReturnValue 74 | public Builder values(String... values) { 75 | return values(Arrays.asList(values)); 76 | } 77 | 78 | @ExcludeFromGeneratedCoverageReport 79 | abstract Builder values(Optional> values); 80 | 81 | /** Clears the value of values field. */ 82 | @ExcludeFromGeneratedCoverageReport 83 | @CanIgnoreReturnValue 84 | public Builder clearValues() { 85 | return values(Optional.empty()); 86 | } 87 | 88 | public abstract StringList build(); 89 | } 90 | 91 | /** Deserializes a JSON string to a StringList object. */ 92 | @ExcludeFromGeneratedCoverageReport 93 | public static StringList fromJson(String jsonString) { 94 | return JsonSerializable.fromJsonString(jsonString, StringList.class); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/FileState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonValue; 23 | import com.google.common.base.Ascii; 24 | import java.util.Objects; 25 | 26 | /** State for the lifecycle of a File. */ 27 | public class FileState { 28 | 29 | /** Enum representing the known values for FileState. */ 30 | public enum Known { 31 | STATE_UNSPECIFIED, 32 | 33 | PROCESSING, 34 | 35 | ACTIVE, 36 | 37 | FAILED, 38 | 39 | FILE_STATE_UNSPECIFIED 40 | } 41 | 42 | private Known fileStateEnum; 43 | private final String value; 44 | 45 | @JsonCreator 46 | public FileState(String value) { 47 | this.value = value; 48 | for (Known fileStateEnum : Known.values()) { 49 | if (Ascii.equalsIgnoreCase(fileStateEnum.toString(), value)) { 50 | this.fileStateEnum = fileStateEnum; 51 | break; 52 | } 53 | } 54 | if (this.fileStateEnum == null) { 55 | this.fileStateEnum = Known.FILE_STATE_UNSPECIFIED; 56 | } 57 | } 58 | 59 | public FileState(Known knownValue) { 60 | this.fileStateEnum = knownValue; 61 | this.value = knownValue.toString(); 62 | } 63 | 64 | @ExcludeFromGeneratedCoverageReport 65 | @Override 66 | @JsonValue 67 | public String toString() { 68 | return this.value; 69 | } 70 | 71 | @ExcludeFromGeneratedCoverageReport 72 | @SuppressWarnings("PatternMatchingInstanceof") 73 | @Override 74 | public boolean equals(Object o) { 75 | if (this == o) { 76 | return true; 77 | } 78 | if (o == null) { 79 | return false; 80 | } 81 | 82 | if (!(o instanceof FileState)) { 83 | return false; 84 | } 85 | 86 | FileState other = (FileState) o; 87 | 88 | if (this.fileStateEnum != Known.FILE_STATE_UNSPECIFIED 89 | && other.fileStateEnum != Known.FILE_STATE_UNSPECIFIED) { 90 | return this.fileStateEnum == other.fileStateEnum; 91 | } else if (this.fileStateEnum == Known.FILE_STATE_UNSPECIFIED 92 | && other.fileStateEnum == Known.FILE_STATE_UNSPECIFIED) { 93 | return this.value.equals(other.value); 94 | } 95 | return false; 96 | } 97 | 98 | @ExcludeFromGeneratedCoverageReport 99 | @Override 100 | public int hashCode() { 101 | if (this.fileStateEnum != Known.FILE_STATE_UNSPECIFIED) { 102 | return this.fileStateEnum.hashCode(); 103 | } else { 104 | return Objects.hashCode(this.value); 105 | } 106 | } 107 | 108 | @ExcludeFromGeneratedCoverageReport 109 | public Known knownEnum() { 110 | return this.fileStateEnum; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GetDocumentConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Optional Config. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GetDocumentConfig.Builder.class) 32 | public abstract class GetDocumentConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for GetDocumentConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_GetDocumentConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for GetDocumentConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `GetDocumentConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_GetDocumentConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract GetDocumentConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a GetDocumentConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static GetDocumentConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, GetDocumentConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GetOperationConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** None */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GetOperationConfig.Builder.class) 32 | public abstract class GetOperationConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for GetOperationConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_GetOperationConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for GetOperationConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `GetOperationConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_GetOperationConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract GetOperationConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a GetOperationConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static GetOperationConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, GetOperationConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/LiveServerGoAway.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.time.Duration; 28 | import java.util.Optional; 29 | 30 | /** Server will not be able to service client soon. */ 31 | @AutoValue 32 | @JsonDeserialize(builder = LiveServerGoAway.Builder.class) 33 | public abstract class LiveServerGoAway extends JsonSerializable { 34 | /** 35 | * The remaining time before the connection will be terminated as ABORTED. The minimal time 36 | * returned here is specified differently together with the rate limits for a given model. 37 | */ 38 | @JsonProperty("timeLeft") 39 | public abstract Optional timeLeft(); 40 | 41 | /** Instantiates a builder for LiveServerGoAway. */ 42 | @ExcludeFromGeneratedCoverageReport 43 | public static Builder builder() { 44 | return new AutoValue_LiveServerGoAway.Builder(); 45 | } 46 | 47 | /** Creates a builder with the same values as this instance. */ 48 | public abstract Builder toBuilder(); 49 | 50 | /** Builder for LiveServerGoAway. */ 51 | @AutoValue.Builder 52 | public abstract static class Builder { 53 | /** For internal usage. Please use `LiveServerGoAway.builder()` for instantiation. */ 54 | @JsonCreator 55 | private static Builder create() { 56 | return new AutoValue_LiveServerGoAway.Builder(); 57 | } 58 | 59 | /** 60 | * Setter for timeLeft. 61 | * 62 | *

timeLeft: The remaining time before the connection will be terminated as ABORTED. The 63 | * minimal time returned here is specified differently together with the rate limits for a given 64 | * model. 65 | */ 66 | @JsonProperty("timeLeft") 67 | public abstract Builder timeLeft(Duration timeLeft); 68 | 69 | @ExcludeFromGeneratedCoverageReport 70 | abstract Builder timeLeft(Optional timeLeft); 71 | 72 | /** Clears the value of timeLeft field. */ 73 | @ExcludeFromGeneratedCoverageReport 74 | @CanIgnoreReturnValue 75 | public Builder clearTimeLeft() { 76 | return timeLeft(Optional.empty()); 77 | } 78 | 79 | public abstract LiveServerGoAway build(); 80 | } 81 | 82 | /** Deserializes a JSON string to a LiveServerGoAway object. */ 83 | @ExcludeFromGeneratedCoverageReport 84 | public static LiveServerGoAway fromJson(String jsonString) { 85 | return JsonSerializable.fromJsonString(jsonString, LiveServerGoAway.class); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GetBatchJobConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Optional parameters. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GetBatchJobConfig.Builder.class) 32 | public abstract class GetBatchJobConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for GetBatchJobConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_GetBatchJobConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for GetBatchJobConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `GetBatchJobConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_GetBatchJobConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract GetBatchJobConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a GetBatchJobConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static GetBatchJobConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, GetBatchJobConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/Language.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonValue; 23 | import com.google.common.base.Ascii; 24 | import java.util.Objects; 25 | 26 | /** Programming language of the `code`. */ 27 | public class Language { 28 | 29 | /** Enum representing the known values for Language. */ 30 | public enum Known { 31 | /** Unspecified language. This value should not be used. */ 32 | LANGUAGE_UNSPECIFIED, 33 | 34 | /** Python >= 3.10, with numpy and simpy available. */ 35 | PYTHON 36 | } 37 | 38 | private Known languageEnum; 39 | private final String value; 40 | 41 | @JsonCreator 42 | public Language(String value) { 43 | this.value = value; 44 | for (Known languageEnum : Known.values()) { 45 | if (Ascii.equalsIgnoreCase(languageEnum.toString(), value)) { 46 | this.languageEnum = languageEnum; 47 | break; 48 | } 49 | } 50 | if (this.languageEnum == null) { 51 | this.languageEnum = Known.LANGUAGE_UNSPECIFIED; 52 | } 53 | } 54 | 55 | public Language(Known knownValue) { 56 | this.languageEnum = knownValue; 57 | this.value = knownValue.toString(); 58 | } 59 | 60 | @ExcludeFromGeneratedCoverageReport 61 | @Override 62 | @JsonValue 63 | public String toString() { 64 | return this.value; 65 | } 66 | 67 | @ExcludeFromGeneratedCoverageReport 68 | @SuppressWarnings("PatternMatchingInstanceof") 69 | @Override 70 | public boolean equals(Object o) { 71 | if (this == o) { 72 | return true; 73 | } 74 | if (o == null) { 75 | return false; 76 | } 77 | 78 | if (!(o instanceof Language)) { 79 | return false; 80 | } 81 | 82 | Language other = (Language) o; 83 | 84 | if (this.languageEnum != Known.LANGUAGE_UNSPECIFIED 85 | && other.languageEnum != Known.LANGUAGE_UNSPECIFIED) { 86 | return this.languageEnum == other.languageEnum; 87 | } else if (this.languageEnum == Known.LANGUAGE_UNSPECIFIED 88 | && other.languageEnum == Known.LANGUAGE_UNSPECIFIED) { 89 | return this.value.equals(other.value); 90 | } 91 | return false; 92 | } 93 | 94 | @ExcludeFromGeneratedCoverageReport 95 | @Override 96 | public int hashCode() { 97 | if (this.languageEnum != Known.LANGUAGE_UNSPECIFIED) { 98 | return this.languageEnum.hashCode(); 99 | } else { 100 | return Objects.hashCode(this.value); 101 | } 102 | } 103 | 104 | @ExcludeFromGeneratedCoverageReport 105 | public Known knownEnum() { 106 | return this.languageEnum; 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ListTuningJobsParameters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.api.core.InternalApi; 25 | import com.google.auto.value.AutoValue; 26 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 27 | import com.google.genai.JsonSerializable; 28 | import java.util.Optional; 29 | 30 | /** Parameters for the list tuning jobs method. */ 31 | @AutoValue 32 | @InternalApi 33 | @JsonDeserialize(builder = ListTuningJobsParameters.Builder.class) 34 | public abstract class ListTuningJobsParameters extends JsonSerializable { 35 | /** */ 36 | @JsonProperty("config") 37 | public abstract Optional config(); 38 | 39 | /** Instantiates a builder for ListTuningJobsParameters. */ 40 | @ExcludeFromGeneratedCoverageReport 41 | public static Builder builder() { 42 | return new AutoValue_ListTuningJobsParameters.Builder(); 43 | } 44 | 45 | /** Creates a builder with the same values as this instance. */ 46 | public abstract Builder toBuilder(); 47 | 48 | /** Builder for ListTuningJobsParameters. */ 49 | @AutoValue.Builder 50 | public abstract static class Builder { 51 | /** For internal usage. Please use `ListTuningJobsParameters.builder()` for instantiation. */ 52 | @JsonCreator 53 | private static Builder create() { 54 | return new AutoValue_ListTuningJobsParameters.Builder(); 55 | } 56 | 57 | /** 58 | * Setter for config. 59 | * 60 | *

config: 61 | */ 62 | @JsonProperty("config") 63 | public abstract Builder config(ListTuningJobsConfig config); 64 | 65 | /** 66 | * Setter for config builder. 67 | * 68 | *

config: 69 | */ 70 | @CanIgnoreReturnValue 71 | public Builder config(ListTuningJobsConfig.Builder configBuilder) { 72 | return config(configBuilder.build()); 73 | } 74 | 75 | @ExcludeFromGeneratedCoverageReport 76 | abstract Builder config(Optional config); 77 | 78 | /** Clears the value of config field. */ 79 | @ExcludeFromGeneratedCoverageReport 80 | @CanIgnoreReturnValue 81 | public Builder clearConfig() { 82 | return config(Optional.empty()); 83 | } 84 | 85 | public abstract ListTuningJobsParameters build(); 86 | } 87 | 88 | /** Deserializes a JSON string to a ListTuningJobsParameters object. */ 89 | @ExcludeFromGeneratedCoverageReport 90 | public static ListTuningJobsParameters fromJson(String jsonString) { 91 | return JsonSerializable.fromJsonString(jsonString, ListTuningJobsParameters.class); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/DeleteFileConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Used to override the default configuration. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = DeleteFileConfig.Builder.class) 32 | public abstract class DeleteFileConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for DeleteFileConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_DeleteFileConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for DeleteFileConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `DeleteFileConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_DeleteFileConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract DeleteFileConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a DeleteFileConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static DeleteFileConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, DeleteFileConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/DeleteModelConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Configuration for deleting a tuned model. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = DeleteModelConfig.Builder.class) 32 | public abstract class DeleteModelConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for DeleteModelConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_DeleteModelConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for DeleteModelConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `DeleteModelConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_DeleteModelConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract DeleteModelConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a DeleteModelConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static DeleteModelConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, DeleteModelConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/CancelBatchJobConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Optional parameters. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = CancelBatchJobConfig.Builder.class) 32 | public abstract class CancelBatchJobConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for CancelBatchJobConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_CancelBatchJobConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for CancelBatchJobConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `CancelBatchJobConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_CancelBatchJobConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract CancelBatchJobConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a CancelBatchJobConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static CancelBatchJobConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, CancelBatchJobConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/DownloadFileConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Used to override the default configuration. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = DownloadFileConfig.Builder.class) 32 | public abstract class DownloadFileConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for DownloadFileConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_DownloadFileConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for DownloadFileConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `DownloadFileConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_DownloadFileConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract DownloadFileConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a DownloadFileConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static DownloadFileConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, DownloadFileConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GcsDestination.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** The Google Cloud Storage location where the output is to be written to. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GcsDestination.Builder.class) 32 | public abstract class GcsDestination extends JsonSerializable { 33 | /** 34 | * Required. Google Cloud Storage URI to output directory. If the uri doesn't end with '/', a '/' 35 | * will be automatically appended. The directory is created if it doesn't exist. 36 | */ 37 | @JsonProperty("outputUriPrefix") 38 | public abstract Optional outputUriPrefix(); 39 | 40 | /** Instantiates a builder for GcsDestination. */ 41 | @ExcludeFromGeneratedCoverageReport 42 | public static Builder builder() { 43 | return new AutoValue_GcsDestination.Builder(); 44 | } 45 | 46 | /** Creates a builder with the same values as this instance. */ 47 | public abstract Builder toBuilder(); 48 | 49 | /** Builder for GcsDestination. */ 50 | @AutoValue.Builder 51 | public abstract static class Builder { 52 | /** For internal usage. Please use `GcsDestination.builder()` for instantiation. */ 53 | @JsonCreator 54 | private static Builder create() { 55 | return new AutoValue_GcsDestination.Builder(); 56 | } 57 | 58 | /** 59 | * Setter for outputUriPrefix. 60 | * 61 | *

outputUriPrefix: Required. Google Cloud Storage URI to output directory. If the uri 62 | * doesn't end with '/', a '/' will be automatically appended. The directory is created if it 63 | * doesn't exist. 64 | */ 65 | @JsonProperty("outputUriPrefix") 66 | public abstract Builder outputUriPrefix(String outputUriPrefix); 67 | 68 | @ExcludeFromGeneratedCoverageReport 69 | abstract Builder outputUriPrefix(Optional outputUriPrefix); 70 | 71 | /** Clears the value of outputUriPrefix field. */ 72 | @ExcludeFromGeneratedCoverageReport 73 | @CanIgnoreReturnValue 74 | public Builder clearOutputUriPrefix() { 75 | return outputUriPrefix(Optional.empty()); 76 | } 77 | 78 | public abstract GcsDestination build(); 79 | } 80 | 81 | /** Deserializes a JSON string to a GcsDestination object. */ 82 | @ExcludeFromGeneratedCoverageReport 83 | public static GcsDestination fromJson(String jsonString) { 84 | return JsonSerializable.fromJsonString(jsonString, GcsDestination.class); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/GetTuningJobConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Optional parameters for tunings.get method. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = GetTuningJobConfig.Builder.class) 32 | public abstract class GetTuningJobConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for GetTuningJobConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_GetTuningJobConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for GetTuningJobConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `GetTuningJobConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_GetTuningJobConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract GetTuningJobConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a GetTuningJobConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static GetTuningJobConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, GetTuningJobConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ApiAuth.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** 30 | * The generic reusable api auth config. Deprecated. Please use AuthConfig 31 | * (google/cloud/aiplatform/master/auth.proto) instead. This data type is not supported in Gemini 32 | * API. 33 | */ 34 | @AutoValue 35 | @JsonDeserialize(builder = ApiAuth.Builder.class) 36 | public abstract class ApiAuth extends JsonSerializable { 37 | /** The API secret. */ 38 | @JsonProperty("apiKeyConfig") 39 | public abstract Optional apiKeyConfig(); 40 | 41 | /** Instantiates a builder for ApiAuth. */ 42 | @ExcludeFromGeneratedCoverageReport 43 | public static Builder builder() { 44 | return new AutoValue_ApiAuth.Builder(); 45 | } 46 | 47 | /** Creates a builder with the same values as this instance. */ 48 | public abstract Builder toBuilder(); 49 | 50 | /** Builder for ApiAuth. */ 51 | @AutoValue.Builder 52 | public abstract static class Builder { 53 | /** For internal usage. Please use `ApiAuth.builder()` for instantiation. */ 54 | @JsonCreator 55 | private static Builder create() { 56 | return new AutoValue_ApiAuth.Builder(); 57 | } 58 | 59 | /** 60 | * Setter for apiKeyConfig. 61 | * 62 | *

apiKeyConfig: The API secret. 63 | */ 64 | @JsonProperty("apiKeyConfig") 65 | public abstract Builder apiKeyConfig(ApiAuthApiKeyConfig apiKeyConfig); 66 | 67 | /** 68 | * Setter for apiKeyConfig builder. 69 | * 70 | *

apiKeyConfig: The API secret. 71 | */ 72 | @CanIgnoreReturnValue 73 | public Builder apiKeyConfig(ApiAuthApiKeyConfig.Builder apiKeyConfigBuilder) { 74 | return apiKeyConfig(apiKeyConfigBuilder.build()); 75 | } 76 | 77 | @ExcludeFromGeneratedCoverageReport 78 | abstract Builder apiKeyConfig(Optional apiKeyConfig); 79 | 80 | /** Clears the value of apiKeyConfig field. */ 81 | @ExcludeFromGeneratedCoverageReport 82 | @CanIgnoreReturnValue 83 | public Builder clearApiKeyConfig() { 84 | return apiKeyConfig(Optional.empty()); 85 | } 86 | 87 | public abstract ApiAuth build(); 88 | } 89 | 90 | /** Deserializes a JSON string to a ApiAuth object. */ 91 | @ExcludeFromGeneratedCoverageReport 92 | public static ApiAuth fromJson(String jsonString) { 93 | return JsonSerializable.fromJsonString(jsonString, ApiAuth.class); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/RagRetrievalConfigRankingRankService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Config for Rank Service. This data type is not supported in Gemini API. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = RagRetrievalConfigRankingRankService.Builder.class) 32 | public abstract class RagRetrievalConfigRankingRankService extends JsonSerializable { 33 | /** Optional. The model name of the rank service. Format: `semantic-ranker-512@latest` */ 34 | @JsonProperty("modelName") 35 | public abstract Optional modelName(); 36 | 37 | /** Instantiates a builder for RagRetrievalConfigRankingRankService. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_RagRetrievalConfigRankingRankService.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for RagRetrievalConfigRankingRankService. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** 50 | * For internal usage. Please use `RagRetrievalConfigRankingRankService.builder()` for 51 | * instantiation. 52 | */ 53 | @JsonCreator 54 | private static Builder create() { 55 | return new AutoValue_RagRetrievalConfigRankingRankService.Builder(); 56 | } 57 | 58 | /** 59 | * Setter for modelName. 60 | * 61 | *

modelName: Optional. The model name of the rank service. Format: 62 | * `semantic-ranker-512@latest` 63 | */ 64 | @JsonProperty("modelName") 65 | public abstract Builder modelName(String modelName); 66 | 67 | @ExcludeFromGeneratedCoverageReport 68 | abstract Builder modelName(Optional modelName); 69 | 70 | /** Clears the value of modelName field. */ 71 | @ExcludeFromGeneratedCoverageReport 72 | @CanIgnoreReturnValue 73 | public Builder clearModelName() { 74 | return modelName(Optional.empty()); 75 | } 76 | 77 | public abstract RagRetrievalConfigRankingRankService build(); 78 | } 79 | 80 | /** Deserializes a JSON string to a RagRetrievalConfigRankingRankService object. */ 81 | @ExcludeFromGeneratedCoverageReport 82 | public static RagRetrievalConfigRankingRankService fromJson(String jsonString) { 83 | return JsonSerializable.fromJsonString(jsonString, RagRetrievalConfigRankingRankService.class); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/ComputeTokensConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Optional parameters for computing tokens. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = ComputeTokensConfig.Builder.class) 32 | public abstract class ComputeTokensConfig extends JsonSerializable { 33 | /** Used to override HTTP request options. */ 34 | @JsonProperty("httpOptions") 35 | public abstract Optional httpOptions(); 36 | 37 | /** Instantiates a builder for ComputeTokensConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_ComputeTokensConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for ComputeTokensConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `ComputeTokensConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_ComputeTokensConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for httpOptions. 57 | * 58 | *

httpOptions: Used to override HTTP request options. 59 | */ 60 | @JsonProperty("httpOptions") 61 | public abstract Builder httpOptions(HttpOptions httpOptions); 62 | 63 | /** 64 | * Setter for httpOptions builder. 65 | * 66 | *

httpOptions: Used to override HTTP request options. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder httpOptions(HttpOptions.Builder httpOptionsBuilder) { 70 | return httpOptions(httpOptionsBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder httpOptions(Optional httpOptions); 75 | 76 | /** Clears the value of httpOptions field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearHttpOptions() { 80 | return httpOptions(Optional.empty()); 81 | } 82 | 83 | public abstract ComputeTokensConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a ComputeTokensConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static ComputeTokensConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, ComputeTokensConfig.class); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/main/java/com/google/genai/types/OutputConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2025 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Auto-generated code. Do not edit. 18 | 19 | package com.google.genai.types; 20 | 21 | import com.fasterxml.jackson.annotation.JsonCreator; 22 | import com.fasterxml.jackson.annotation.JsonProperty; 23 | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 24 | import com.google.auto.value.AutoValue; 25 | import com.google.errorprone.annotations.CanIgnoreReturnValue; 26 | import com.google.genai.JsonSerializable; 27 | import java.util.Optional; 28 | 29 | /** Config for evaluation output. */ 30 | @AutoValue 31 | @JsonDeserialize(builder = OutputConfig.Builder.class) 32 | public abstract class OutputConfig extends JsonSerializable { 33 | /** Cloud storage destination for evaluation output. */ 34 | @JsonProperty("gcsDestination") 35 | public abstract Optional gcsDestination(); 36 | 37 | /** Instantiates a builder for OutputConfig. */ 38 | @ExcludeFromGeneratedCoverageReport 39 | public static Builder builder() { 40 | return new AutoValue_OutputConfig.Builder(); 41 | } 42 | 43 | /** Creates a builder with the same values as this instance. */ 44 | public abstract Builder toBuilder(); 45 | 46 | /** Builder for OutputConfig. */ 47 | @AutoValue.Builder 48 | public abstract static class Builder { 49 | /** For internal usage. Please use `OutputConfig.builder()` for instantiation. */ 50 | @JsonCreator 51 | private static Builder create() { 52 | return new AutoValue_OutputConfig.Builder(); 53 | } 54 | 55 | /** 56 | * Setter for gcsDestination. 57 | * 58 | *

gcsDestination: Cloud storage destination for evaluation output. 59 | */ 60 | @JsonProperty("gcsDestination") 61 | public abstract Builder gcsDestination(GcsDestination gcsDestination); 62 | 63 | /** 64 | * Setter for gcsDestination builder. 65 | * 66 | *

gcsDestination: Cloud storage destination for evaluation output. 67 | */ 68 | @CanIgnoreReturnValue 69 | public Builder gcsDestination(GcsDestination.Builder gcsDestinationBuilder) { 70 | return gcsDestination(gcsDestinationBuilder.build()); 71 | } 72 | 73 | @ExcludeFromGeneratedCoverageReport 74 | abstract Builder gcsDestination(Optional gcsDestination); 75 | 76 | /** Clears the value of gcsDestination field. */ 77 | @ExcludeFromGeneratedCoverageReport 78 | @CanIgnoreReturnValue 79 | public Builder clearGcsDestination() { 80 | return gcsDestination(Optional.empty()); 81 | } 82 | 83 | public abstract OutputConfig build(); 84 | } 85 | 86 | /** Deserializes a JSON string to a OutputConfig object. */ 87 | @ExcludeFromGeneratedCoverageReport 88 | public static OutputConfig fromJson(String jsonString) { 89 | return JsonSerializable.fromJsonString(jsonString, OutputConfig.class); 90 | } 91 | } 92 | --------------------------------------------------------------------------------