@firebase/ai 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/README.md +5 -0
  2. package/dist/ai-public.d.ts +1972 -0
  3. package/dist/ai.d.ts +2073 -0
  4. package/dist/esm/index.esm2017.js +2624 -0
  5. package/dist/esm/index.esm2017.js.map +1 -0
  6. package/dist/esm/package.json +1 -0
  7. package/dist/esm/src/api.d.ts +120 -0
  8. package/dist/esm/src/backend.d.ts +74 -0
  9. package/dist/esm/src/constants.d.ts +23 -0
  10. package/dist/esm/src/errors.d.ts +35 -0
  11. package/dist/esm/src/googleai-mappers.d.ts +73 -0
  12. package/dist/esm/src/helpers.d.ts +30 -0
  13. package/dist/esm/src/index.d.ts +12 -0
  14. package/dist/esm/src/index.node.d.ts +7 -0
  15. package/dist/esm/src/logger.d.ts +18 -0
  16. package/dist/esm/src/methods/chat-session-helpers.d.ts +18 -0
  17. package/dist/esm/src/methods/chat-session.d.ts +50 -0
  18. package/dist/esm/src/methods/count-tokens.d.ts +19 -0
  19. package/dist/esm/src/methods/generate-content.d.ts +20 -0
  20. package/dist/esm/src/models/ai-model.d.ts +72 -0
  21. package/dist/esm/src/models/generative-model.d.ts +54 -0
  22. package/dist/esm/src/models/imagen-model.d.ts +102 -0
  23. package/dist/esm/src/models/index.d.ts +19 -0
  24. package/dist/esm/src/public-types.d.ts +106 -0
  25. package/dist/esm/src/requests/imagen-image-format.d.ts +61 -0
  26. package/dist/esm/src/requests/request-helpers.d.ts +28 -0
  27. package/dist/esm/src/requests/request.d.ts +43 -0
  28. package/dist/esm/src/requests/response-helpers.d.ts +53 -0
  29. package/dist/esm/src/requests/schema-builder.d.ts +145 -0
  30. package/dist/esm/src/requests/stream-reader.d.ts +38 -0
  31. package/dist/esm/src/service.d.ts +31 -0
  32. package/dist/esm/src/types/content.d.ts +144 -0
  33. package/dist/esm/src/types/enums.d.ts +263 -0
  34. package/dist/esm/src/types/error.d.ts +81 -0
  35. package/dist/esm/src/types/googleai.d.ts +56 -0
  36. package/dist/esm/src/types/imagen/index.d.ts +18 -0
  37. package/dist/esm/src/types/imagen/internal.d.ts +124 -0
  38. package/dist/esm/src/types/imagen/requests.d.ts +211 -0
  39. package/dist/esm/src/types/imagen/responses.d.ts +78 -0
  40. package/dist/esm/src/types/index.d.ts +24 -0
  41. package/dist/esm/src/types/internal.d.ts +33 -0
  42. package/dist/esm/src/types/requests.d.ts +213 -0
  43. package/dist/esm/src/types/responses.d.ts +257 -0
  44. package/dist/esm/src/types/schema.d.ts +102 -0
  45. package/dist/index.cjs.js +2652 -0
  46. package/dist/index.cjs.js.map +1 -0
  47. package/dist/index.node.cjs.js +2652 -0
  48. package/dist/index.node.cjs.js.map +1 -0
  49. package/dist/index.node.mjs +2624 -0
  50. package/dist/index.node.mjs.map +1 -0
  51. package/dist/src/api.d.ts +120 -0
  52. package/dist/src/backend.d.ts +74 -0
  53. package/dist/src/constants.d.ts +23 -0
  54. package/dist/src/errors.d.ts +35 -0
  55. package/dist/src/googleai-mappers.d.ts +73 -0
  56. package/dist/src/helpers.d.ts +30 -0
  57. package/dist/src/index.d.ts +12 -0
  58. package/dist/src/index.node.d.ts +7 -0
  59. package/dist/src/logger.d.ts +18 -0
  60. package/dist/src/methods/chat-session-helpers.d.ts +18 -0
  61. package/dist/src/methods/chat-session.d.ts +50 -0
  62. package/dist/src/methods/count-tokens.d.ts +19 -0
  63. package/dist/src/methods/generate-content.d.ts +20 -0
  64. package/dist/src/models/ai-model.d.ts +72 -0
  65. package/dist/src/models/generative-model.d.ts +54 -0
  66. package/dist/src/models/imagen-model.d.ts +102 -0
  67. package/dist/src/models/index.d.ts +19 -0
  68. package/dist/src/public-types.d.ts +106 -0
  69. package/dist/src/requests/imagen-image-format.d.ts +61 -0
  70. package/dist/src/requests/request-helpers.d.ts +28 -0
  71. package/dist/src/requests/request.d.ts +43 -0
  72. package/dist/src/requests/response-helpers.d.ts +53 -0
  73. package/dist/src/requests/schema-builder.d.ts +145 -0
  74. package/dist/src/requests/stream-reader.d.ts +38 -0
  75. package/dist/src/service.d.ts +31 -0
  76. package/dist/src/tsdoc-metadata.json +11 -0
  77. package/dist/src/types/content.d.ts +144 -0
  78. package/dist/src/types/enums.d.ts +263 -0
  79. package/dist/src/types/error.d.ts +81 -0
  80. package/dist/src/types/googleai.d.ts +56 -0
  81. package/dist/src/types/imagen/index.d.ts +18 -0
  82. package/dist/src/types/imagen/internal.d.ts +124 -0
  83. package/dist/src/types/imagen/requests.d.ts +211 -0
  84. package/dist/src/types/imagen/responses.d.ts +78 -0
  85. package/dist/src/types/index.d.ts +24 -0
  86. package/dist/src/types/internal.d.ts +33 -0
  87. package/dist/src/types/requests.d.ts +213 -0
  88. package/dist/src/types/responses.d.ts +257 -0
  89. package/dist/src/types/schema.d.ts +102 -0
  90. package/package.json +81 -0
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export declare const AI_TYPE = "AI";
18
+ export declare const DEFAULT_LOCATION = "us-central1";
19
+ export declare const DEFAULT_BASE_URL = "https://firebasevertexai.googleapis.com";
20
+ export declare const DEFAULT_API_VERSION = "v1beta";
21
+ export declare const PACKAGE_VERSION: string;
22
+ export declare const LANGUAGE_TAG = "gl-js";
23
+ export declare const DEFAULT_FETCH_TIMEOUT_MS: number;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseError } from '@firebase/util';
18
+ import { AIErrorCode, CustomErrorData } from './types';
19
+ /**
20
+ * Error class for the Firebase AI SDK.
21
+ *
22
+ * @public
23
+ */
24
+ export declare class AIError extends FirebaseError {
25
+ readonly code: AIErrorCode;
26
+ readonly customErrorData?: CustomErrorData | undefined;
27
+ /**
28
+ * Constructs a new instance of the `AIError` class.
29
+ *
30
+ * @param code - The error code from {@link AIErrorCode}.
31
+ * @param message - A human-readable message describing the error.
32
+ * @param customErrorData - Optional error data.
33
+ */
34
+ constructor(code: AIErrorCode, message: string, customErrorData?: CustomErrorData | undefined);
35
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { CountTokensRequest, GenerateContentCandidate, GenerateContentRequest, GenerateContentResponse, PromptFeedback } from './types';
18
+ import { GoogleAIGenerateContentResponse, GoogleAIGenerateContentCandidate, GoogleAICountTokensRequest } from './types/googleai';
19
+ /**
20
+ * This SDK supports both the Vertex AI Gemini API and the Gemini Developer API (using Google AI).
21
+ * The public API prioritizes the format used by the Vertex AI Gemini API.
22
+ * We avoid having two sets of types by translating requests and responses between the two API formats.
23
+ * This translation allows developers to switch between the Vertex AI Gemini API and the Gemini Developer API
24
+ * with minimal code changes.
25
+ *
26
+ * In here are functions that map requests and responses between the two API formats.
27
+ * Requests in the Vertex AI format are mapped to the Google AI format before being sent.
28
+ * Responses from the Google AI backend are mapped back to the Vertex AI format before being returned to the user.
29
+ */
30
+ /**
31
+ * Maps a Vertex AI {@link GenerateContentRequest} to a format that can be sent to Google AI.
32
+ *
33
+ * @param generateContentRequest The {@link GenerateContentRequest} to map.
34
+ * @returns A {@link GenerateContentResponse} that conforms to the Google AI format.
35
+ *
36
+ * @throws If the request contains properties that are unsupported by Google AI.
37
+ *
38
+ * @internal
39
+ */
40
+ export declare function mapGenerateContentRequest(generateContentRequest: GenerateContentRequest): GenerateContentRequest;
41
+ /**
42
+ * Maps a {@link GenerateContentResponse} from Google AI to the format of the
43
+ * {@link GenerateContentResponse} that we get from VertexAI that is exposed in the public API.
44
+ *
45
+ * @param googleAIResponse The {@link GenerateContentResponse} from Google AI.
46
+ * @returns A {@link GenerateContentResponse} that conforms to the public API's format.
47
+ *
48
+ * @internal
49
+ */
50
+ export declare function mapGenerateContentResponse(googleAIResponse: GoogleAIGenerateContentResponse): GenerateContentResponse;
51
+ /**
52
+ * Maps a Vertex AI {@link CountTokensRequest} to a format that can be sent to Google AI.
53
+ *
54
+ * @param countTokensRequest The {@link CountTokensRequest} to map.
55
+ * @param model The model to count tokens with.
56
+ * @returns A {@link CountTokensRequest} that conforms to the Google AI format.
57
+ *
58
+ * @internal
59
+ */
60
+ export declare function mapCountTokensRequest(countTokensRequest: CountTokensRequest, model: string): GoogleAICountTokensRequest;
61
+ /**
62
+ * Maps a Google AI {@link GoogleAIGenerateContentCandidate} to a format that conforms
63
+ * to the Vertex AI API format.
64
+ *
65
+ * @param candidates The {@link GoogleAIGenerateContentCandidate} to map.
66
+ * @returns A {@link GenerateContentCandidate} that conforms to the Vertex AI format.
67
+ *
68
+ * @throws If any {@link Part} in the candidates has a `videoMetadata` property.
69
+ *
70
+ * @internal
71
+ */
72
+ export declare function mapGenerateContentCandidates(candidates: GoogleAIGenerateContentCandidate[]): GenerateContentCandidate[];
73
+ export declare function mapPromptFeedback(promptFeedback: PromptFeedback): PromptFeedback;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Backend } from './backend';
18
+ /**
19
+ * Encodes a {@link Backend} into a string that will be used to uniquely identify {@link AI}
20
+ * instances by backend type.
21
+ *
22
+ * @internal
23
+ */
24
+ export declare function encodeInstanceIdentifier(backend: Backend): string;
25
+ /**
26
+ * Decodes an instance identifier string into a {@link Backend}.
27
+ *
28
+ * @internal
29
+ */
30
+ export declare function decodeInstanceIdentifier(instanceIdentifier: string): Backend;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * The Firebase AI Web SDK.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ declare global {
7
+ interface Window {
8
+ [key: string]: unknown;
9
+ }
10
+ }
11
+ export * from './api';
12
+ export * from './public-types';
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The Firebase AI Web SDK.
3
+ *
4
+ * @packageDocumentation
5
+ */
6
+ export * from './api';
7
+ export * from './public-types';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Logger } from '@firebase/logger';
18
+ export declare const logger: Logger;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Content } from '../types';
18
+ export declare function validateChatHistory(history: Content[]): void;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Content, GenerateContentResult, GenerateContentStreamResult, Part, RequestOptions, StartChatParams } from '../types';
18
+ import { ApiSettings } from '../types/internal';
19
+ /**
20
+ * ChatSession class that enables sending chat messages and stores
21
+ * history of sent and received messages so far.
22
+ *
23
+ * @public
24
+ */
25
+ export declare class ChatSession {
26
+ model: string;
27
+ params?: StartChatParams | undefined;
28
+ requestOptions?: RequestOptions | undefined;
29
+ private _apiSettings;
30
+ private _history;
31
+ private _sendPromise;
32
+ constructor(apiSettings: ApiSettings, model: string, params?: StartChatParams | undefined, requestOptions?: RequestOptions | undefined);
33
+ /**
34
+ * Gets the chat history so far. Blocked prompts are not added to history.
35
+ * Neither blocked candidates nor the prompts that generated them are added
36
+ * to history.
37
+ */
38
+ getHistory(): Promise<Content[]>;
39
+ /**
40
+ * Sends a chat message and receives a non-streaming
41
+ * {@link GenerateContentResult}
42
+ */
43
+ sendMessage(request: string | Array<string | Part>): Promise<GenerateContentResult>;
44
+ /**
45
+ * Sends a chat message and receives the response as a
46
+ * {@link GenerateContentStreamResult} containing an iterable stream
47
+ * and a response promise.
48
+ */
49
+ sendMessageStream(request: string | Array<string | Part>): Promise<GenerateContentStreamResult>;
50
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { CountTokensRequest, CountTokensResponse, RequestOptions } from '../types';
18
+ import { ApiSettings } from '../types/internal';
19
+ export declare function countTokens(apiSettings: ApiSettings, model: string, params: CountTokensRequest, requestOptions?: RequestOptions): Promise<CountTokensResponse>;
@@ -0,0 +1,20 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { GenerateContentRequest, GenerateContentResult, GenerateContentStreamResult, RequestOptions } from '../types';
18
+ import { ApiSettings } from '../types/internal';
19
+ export declare function generateContentStream(apiSettings: ApiSettings, model: string, params: GenerateContentRequest, requestOptions?: RequestOptions): Promise<GenerateContentStreamResult>;
20
+ export declare function generateContent(apiSettings: ApiSettings, model: string, params: GenerateContentRequest, requestOptions?: RequestOptions): Promise<GenerateContentResult>;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { AI, BackendType } from '../public-types';
18
+ import { ApiSettings } from '../types/internal';
19
+ /**
20
+ * Base class for Firebase AI model APIs.
21
+ *
22
+ * Instances of this class are associated with a specific Firebase AI {@link Backend}
23
+ * and provide methods for interacting with the configured generative model.
24
+ *
25
+ * @public
26
+ */
27
+ export declare abstract class AIModel {
28
+ /**
29
+ * The fully qualified model resource name to use for generating images
30
+ * (for example, `publishers/google/models/imagen-3.0-generate-002`).
31
+ */
32
+ readonly model: string;
33
+ /**
34
+ * @internal
35
+ */
36
+ protected _apiSettings: ApiSettings;
37
+ /**
38
+ * Constructs a new instance of the {@link AIModel} class.
39
+ *
40
+ * This constructor should only be called from subclasses that provide
41
+ * a model API.
42
+ *
43
+ * @param ai - an {@link AI} instance.
44
+ * @param modelName - The name of the model being used. It can be in one of the following formats:
45
+ * - `my-model` (short name, will resolve to `publishers/google/models/my-model`)
46
+ * - `models/my-model` (will resolve to `publishers/google/models/my-model`)
47
+ * - `publishers/my-publisher/models/my-model` (fully qualified model name)
48
+ *
49
+ * @throws If the `apiKey` or `projectId` fields are missing in your
50
+ * Firebase config.
51
+ *
52
+ * @internal
53
+ */
54
+ protected constructor(ai: AI, modelName: string);
55
+ /**
56
+ * Normalizes the given model name to a fully qualified model resource name.
57
+ *
58
+ * @param modelName - The model name to normalize.
59
+ * @returns The fully qualified model resource name.
60
+ *
61
+ * @internal
62
+ */
63
+ static normalizeModelName(modelName: string, backendType: BackendType): string;
64
+ /**
65
+ * @internal
66
+ */
67
+ private static normalizeGoogleAIModelName;
68
+ /**
69
+ * @internal
70
+ */
71
+ private static normalizeVertexAIModelName;
72
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { Content, CountTokensRequest, CountTokensResponse, GenerateContentRequest, GenerateContentResult, GenerateContentStreamResult, GenerationConfig, ModelParams, Part, RequestOptions, SafetySetting, StartChatParams, Tool, ToolConfig } from '../types';
18
+ import { ChatSession } from '../methods/chat-session';
19
+ import { AI } from '../public-types';
20
+ import { AIModel } from './ai-model';
21
+ /**
22
+ * Class for generative model APIs.
23
+ * @public
24
+ */
25
+ export declare class GenerativeModel extends AIModel {
26
+ generationConfig: GenerationConfig;
27
+ safetySettings: SafetySetting[];
28
+ requestOptions?: RequestOptions;
29
+ tools?: Tool[];
30
+ toolConfig?: ToolConfig;
31
+ systemInstruction?: Content;
32
+ constructor(ai: AI, modelParams: ModelParams, requestOptions?: RequestOptions);
33
+ /**
34
+ * Makes a single non-streaming call to the model
35
+ * and returns an object containing a single {@link GenerateContentResponse}.
36
+ */
37
+ generateContent(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentResult>;
38
+ /**
39
+ * Makes a single streaming call to the model
40
+ * and returns an object containing an iterable stream that iterates
41
+ * over all chunks in the streaming response as well as
42
+ * a promise that returns the final aggregated response.
43
+ */
44
+ generateContentStream(request: GenerateContentRequest | string | Array<string | Part>): Promise<GenerateContentStreamResult>;
45
+ /**
46
+ * Gets a new {@link ChatSession} instance which can be used for
47
+ * multi-turn chats.
48
+ */
49
+ startChat(startChatParams?: StartChatParams): ChatSession;
50
+ /**
51
+ * Counts the tokens in the provided request.
52
+ */
53
+ countTokens(request: CountTokensRequest | string | Array<string | Part>): Promise<CountTokensResponse>;
54
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { AI } from '../public-types';
18
+ import { ImagenGCSImage, ImagenGenerationConfig, ImagenInlineImage, RequestOptions, ImagenModelParams, ImagenGenerationResponse, ImagenSafetySettings } from '../types';
19
+ import { AIModel } from './ai-model';
20
+ /**
21
+ * Class for Imagen model APIs.
22
+ *
23
+ * This class provides methods for generating images using the Imagen model.
24
+ *
25
+ * @example
26
+ * ```javascript
27
+ * const imagen = new ImagenModel(
28
+ * ai,
29
+ * {
30
+ * model: 'imagen-3.0-generate-002'
31
+ * }
32
+ * );
33
+ *
34
+ * const response = await imagen.generateImages('A photo of a cat');
35
+ * if (response.images.length > 0) {
36
+ * console.log(response.images[0].bytesBase64Encoded);
37
+ * }
38
+ * ```
39
+ *
40
+ * @beta
41
+ */
42
+ export declare class ImagenModel extends AIModel {
43
+ requestOptions?: RequestOptions | undefined;
44
+ /**
45
+ * The Imagen generation configuration.
46
+ */
47
+ generationConfig?: ImagenGenerationConfig;
48
+ /**
49
+ * Safety settings for filtering inappropriate content.
50
+ */
51
+ safetySettings?: ImagenSafetySettings;
52
+ /**
53
+ * Constructs a new instance of the {@link ImagenModel} class.
54
+ *
55
+ * @param ai - an {@link AI} instance.
56
+ * @param modelParams - Parameters to use when making requests to Imagen.
57
+ * @param requestOptions - Additional options to use when making requests.
58
+ *
59
+ * @throws If the `apiKey` or `projectId` fields are missing in your
60
+ * Firebase config.
61
+ */
62
+ constructor(ai: AI, modelParams: ImagenModelParams, requestOptions?: RequestOptions | undefined);
63
+ /**
64
+ * Generates images using the Imagen model and returns them as
65
+ * base64-encoded strings.
66
+ *
67
+ * @param prompt - A text prompt describing the image(s) to generate.
68
+ * @returns A promise that resolves to an {@link ImagenGenerationResponse}
69
+ * object containing the generated images.
70
+ *
71
+ * @throws If the request to generate images fails. This happens if the
72
+ * prompt is blocked.
73
+ *
74
+ * @remarks
75
+ * If the prompt was not blocked, but one or more of the generated images were filtered, the
76
+ * returned object will have a `filteredReason` property.
77
+ * If all images are filtered, the `images` array will be empty.
78
+ *
79
+ * @beta
80
+ */
81
+ generateImages(prompt: string): Promise<ImagenGenerationResponse<ImagenInlineImage>>;
82
+ /**
83
+ * Generates images to Cloud Storage for Firebase using the Imagen model.
84
+ *
85
+ * @internal This method is temporarily internal.
86
+ *
87
+ * @param prompt - A text prompt describing the image(s) to generate.
88
+ * @param gcsURI - The URI of file stored in a Cloud Storage for Firebase bucket.
89
+ * This should be a directory. For example, `gs://my-bucket/my-directory/`.
90
+ * @returns A promise that resolves to an {@link ImagenGenerationResponse}
91
+ * object containing the URLs of the generated images.
92
+ *
93
+ * @throws If the request fails to generate images fails. This happens if
94
+ * the prompt is blocked.
95
+ *
96
+ * @remarks
97
+ * If the prompt was not blocked, but one or more of the generated images were filtered, the
98
+ * returned object will have a `filteredReason` property.
99
+ * If all images are filtered, the `images` array will be empty.
100
+ */
101
+ generateImagesGCS(prompt: string, gcsURI: string): Promise<ImagenGenerationResponse<ImagenGCSImage>>;
102
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2025 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ export * from './ai-model';
18
+ export * from './generative-model';
19
+ export * from './imagen-model';
@@ -0,0 +1,106 @@
1
+ /**
2
+ * @license
3
+ * Copyright 2024 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { FirebaseApp } from '@firebase/app';
18
+ import { Backend } from './backend';
19
+ export * from './types';
20
+ /**
21
+ * @deprecated Use the new {@link AI | AI} instead. The Vertex AI in Firebase SDK has been
22
+ * replaced with the Firebase AI SDK to accommodate the evolving set of supported features and
23
+ * services. For migration details, see the {@link https://firebase.google.com/docs/vertex-ai/migrate-to-latest-sdk | migration guide}.
24
+ *
25
+ * An instance of the Firebase AI SDK.
26
+ *
27
+ * @public
28
+ */
29
+ export type VertexAI = AI;
30
+ /**
31
+ * Options when initializing the Firebase AI SDK.
32
+ *
33
+ * @public
34
+ */
35
+ export interface VertexAIOptions {
36
+ location?: string;
37
+ }
38
+ /**
39
+ * An instance of the Firebase AI SDK.
40
+ *
41
+ * Do not create this instance directly. Instead, use {@link getAI | getAI()}.
42
+ *
43
+ * @public
44
+ */
45
+ export interface AI {
46
+ /**
47
+ * The {@link @firebase/app#FirebaseApp} this {@link AI} instance is associated with.
48
+ */
49
+ app: FirebaseApp;
50
+ /**
51
+ * A {@link Backend} instance that specifies the configuration for the target backend,
52
+ * either the Gemini Developer API (using {@link GoogleAIBackend}) or the
53
+ * Vertex AI Gemini API (using {@link VertexAIBackend}).
54
+ */
55
+ backend: Backend;
56
+ /**
57
+ * @deprecated use `AI.backend.location` instead.
58
+ *
59
+ * The location configured for this AI service instance, relevant for Vertex AI backends.
60
+ */
61
+ location: string;
62
+ }
63
+ /**
64
+ * An enum-like object containing constants that represent the supported backends
65
+ * for the Firebase AI SDK.
66
+ * This determines which backend service (Vertex AI Gemini API or Gemini Developer API)
67
+ * the SDK will communicate with.
68
+ *
69
+ * These values are assigned to the `backendType` property within the specific backend
70
+ * configuration objects ({@link GoogleAIBackend} or {@link VertexAIBackend}) to identify
71
+ * which service to target.
72
+ *
73
+ * @public
74
+ */
75
+ export declare const BackendType: {
76
+ /**
77
+ * Identifies the backend service for the Vertex AI Gemini API provided through Google Cloud.
78
+ * Use this constant when creating a {@link VertexAIBackend} configuration.
79
+ */
80
+ readonly VERTEX_AI: "VERTEX_AI";
81
+ /**
82
+ * Identifies the backend service for the Gemini Developer API ({@link https://ai.google/ | Google AI}).
83
+ * Use this constant when creating a {@link GoogleAIBackend} configuration.
84
+ */
85
+ readonly GOOGLE_AI: "GOOGLE_AI";
86
+ };
87
+ /**
88
+ * Type alias representing valid backend types.
89
+ * It can be either `'VERTEX_AI'` or `'GOOGLE_AI'`.
90
+ *
91
+ * @public
92
+ */
93
+ export type BackendType = (typeof BackendType)[keyof typeof BackendType];
94
+ /**
95
+ * Options for initializing the AI service using {@link getAI | getAI()}.
96
+ * This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API)
97
+ * and configuring its specific options (like location for Vertex AI).
98
+ *
99
+ * @public
100
+ */
101
+ export interface AIOptions {
102
+ /**
103
+ * The backend configuration to use for the AI service instance.
104
+ */
105
+ backend: Backend;
106
+ }