diff --git a/common/api-review/vertexai.api.md b/common/api-review/vertexai.api.md
index 041bc62451f..10337b453f8 100644
--- a/common/api-review/vertexai.api.md
+++ b/common/api-review/vertexai.api.md
@@ -9,6 +9,12 @@ import { FirebaseApp } from '@firebase/app';
import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
import { FirebaseError } from '@firebase/util';
+// @public
+export enum ApiVersion {
+ V1 = "v1",
+ V1BETA = "v1beta"
+}
+
// @public
export class ArraySchema extends Schema {
constructor(schemaParams: SchemaParams, items: TypedSchema);
@@ -505,6 +511,7 @@ export interface PromptFeedback {
// @public
export interface RequestOptions {
+ apiVersion?: ApiVersion;
baseUrl?: string;
timeout?: number;
}
diff --git a/docs-devsite/vertexai.md b/docs-devsite/vertexai.md
index d9e26eabc5d..c347e312d27 100644
--- a/docs-devsite/vertexai.md
+++ b/docs-devsite/vertexai.md
@@ -40,6 +40,7 @@ The Vertex AI in Firebase Web SDK.
| Enumeration | Description |
| --- | --- |
+| [ApiVersion](./vertexai.md#apiversion) | API versions for the Vertex AI in Firebase endpoint. |
| [BlockReason](./vertexai.md#blockreason) | Reason that a prompt was blocked. |
| [FinishReason](./vertexai.md#finishreason) | Reason that a candidate finished. |
| [FunctionCallingMode](./vertexai.md#functioncallingmode) | |
@@ -217,6 +218,23 @@ A type that includes all specific Schema types.
export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
```
+## ApiVersion
+
+API versions for the Vertex AI in Firebase endpoint.
+
+Signature:
+
+```typescript
+export declare enum ApiVersion
+```
+
+## Enumeration Members
+
+| Member | Value | Description |
+| --- | --- | --- |
+| V1 | "v1"
| The stable channel for version 1 of the API. |
+| V1BETA | "v1beta"
| The beta channel for version 1 of the API. |
+
## BlockReason
Reason that a prompt was blocked.
diff --git a/docs-devsite/vertexai.requestoptions.md b/docs-devsite/vertexai.requestoptions.md
index 6d074775520..d40becc345d 100644
--- a/docs-devsite/vertexai.requestoptions.md
+++ b/docs-devsite/vertexai.requestoptions.md
@@ -22,9 +22,20 @@ export interface RequestOptions
| Property | Type | Description |
| --- | --- | --- |
+| [apiVersion](./vertexai.requestoptions.md#requestoptionsapiversion) | [ApiVersion](./vertexai.md#apiversion) | API version for endpoint. Defaults to "v1beta"
([ApiVersion.V1BETA](./vertexai.md#apiversionv1beta_enummember)
). |
| [baseUrl](./vertexai.requestoptions.md#requestoptionsbaseurl) | string | Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com |
| [timeout](./vertexai.requestoptions.md#requestoptionstimeout) | number | Request timeout in milliseconds. Defaults to 180 seconds (180000ms). |
+## RequestOptions.apiVersion
+
+API version for endpoint. Defaults to "v1beta"
([ApiVersion.V1BETA](./vertexai.md#apiversionv1beta_enummember)
).
+
+Signature:
+
+```typescript
+apiVersion?: ApiVersion;
+```
+
## RequestOptions.baseUrl
Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com
diff --git a/packages/vertexai/src/requests/request.test.ts b/packages/vertexai/src/requests/request.test.ts
index b6d0ecb9b71..79386758118 100644
--- a/packages/vertexai/src/requests/request.test.ts
+++ b/packages/vertexai/src/requests/request.test.ts
@@ -22,7 +22,7 @@ import chaiAsPromised from 'chai-as-promised';
import { RequestUrl, Task, getHeaders, makeRequest } from './request';
import { ApiSettings } from '../types/internal';
import { DEFAULT_API_VERSION } from '../constants';
-import { VertexAIErrorCode } from '../types';
+import { ApiVersion, VertexAIErrorCode } from '../types';
import { VertexAIError } from '../errors';
import { getMockResponse } from '../../test-utils/mock-response';
@@ -74,6 +74,18 @@ describe('request methods', () => {
);
expect(url.toString()).to.include(DEFAULT_API_VERSION);
});
+ it('custom apiVersion', async () => {
+ const url = new RequestUrl(
+ 'models/model-name',
+ Task.GENERATE_CONTENT,
+ fakeApiSettings,
+ false,
+ { apiVersion: ApiVersion.V1 }
+ );
+ expect(url.toString()).to.include(ApiVersion.V1);
+ // TODO: Update test to set ApiVersion.V1BETA when ApiVersion.V1 becomes the default.
+ expect(ApiVersion.V1).to.not.equal(DEFAULT_API_VERSION);
+ });
it('custom baseUrl', async () => {
const url = new RequestUrl(
'models/model-name',
diff --git a/packages/vertexai/src/requests/request.ts b/packages/vertexai/src/requests/request.ts
index f81b40635e3..991a82b18df 100644
--- a/packages/vertexai/src/requests/request.ts
+++ b/packages/vertexai/src/requests/request.ts
@@ -42,8 +42,7 @@ export class RequestUrl {
public requestOptions?: RequestOptions
) {}
toString(): string {
- // TODO: allow user-set option if that feature becomes available
- const apiVersion = DEFAULT_API_VERSION;
+ const apiVersion = this.requestOptions?.apiVersion || DEFAULT_API_VERSION;
const baseUrl = this.requestOptions?.baseUrl || DEFAULT_BASE_URL;
let url = `${baseUrl}/${apiVersion}`;
url += `/projects/${this.apiSettings.project}`;
diff --git a/packages/vertexai/src/types/enums.ts b/packages/vertexai/src/types/enums.ts
index 3e66bacc612..db1361b4c0b 100644
--- a/packages/vertexai/src/types/enums.ts
+++ b/packages/vertexai/src/types/enums.ts
@@ -27,6 +27,17 @@ export type Role = (typeof POSSIBLE_ROLES)[number];
*/
export const POSSIBLE_ROLES = ['user', 'model', 'function', 'system'] as const;
+/**
+ * API versions for the Vertex AI in Firebase endpoint.
+ * @public
+ */
+export enum ApiVersion {
+ /** The stable channel for version 1 of the API. */
+ V1 = 'v1',
+ /** The beta channel for version 1 of the API. */
+ V1BETA = 'v1beta'
+}
+
/**
* Harm categories that would cause prompts or candidates to be blocked.
* @public
diff --git a/packages/vertexai/src/types/requests.ts b/packages/vertexai/src/types/requests.ts
index dc7576f232d..235c9df13c1 100644
--- a/packages/vertexai/src/types/requests.ts
+++ b/packages/vertexai/src/types/requests.ts
@@ -18,6 +18,7 @@
import { TypedSchema } from '../requests/schema-builder';
import { Content, Part } from './content';
import {
+ ApiVersion,
FunctionCallingMode,
HarmBlockMethod,
HarmBlockThreshold,
@@ -129,6 +130,11 @@ export interface RequestOptions {
* Base url for endpoint. Defaults to https://firebasevertexai.googleapis.com
*/
baseUrl?: string;
+ /**
+ * API version for endpoint. Defaults to "v1beta"
+ * ({@link ApiVersion.V1BETA}
).
+ */
+ apiVersion?: ApiVersion;
}
/**