{"_id":"@ai-toolkit/google-vertex","name":"@ai-toolkit/google-vertex","dist-tags":{"latest":"2.1.24"},"versions":{"2.1.24":{"name":"@ai-toolkit/google-vertex","version":"2.1.24","license":"Apache-2.0","sideEffects":false,"main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","exports":{"./package.json":"./package.json",".":{"types":"./dist/index.d.ts","import":"./dist/index.mjs","require":"./dist/index.js"},"./edge":{"types":"./edge/dist/index.d.ts","import":"./edge/dist/index.mjs","require":"./edge/dist/index.js"},"./anthropic":{"types":"./anthropic/dist/index.d.ts","import":"./anthropic/dist/index.mjs","require":"./anthropic/dist/index.js"},"./anthropic/edge":{"types":"./anthropic/edge/dist/index.d.ts","import":"./anthropic/edge/dist/index.mjs","require":"./anthropic/edge/dist/index.js"}},"dependencies":{"@ai-toolkit/anthropic":"1.1.15","@ai-toolkit/google":"1.1.20","@ai-toolkit/provider":"1.0.10","@ai-toolkit/provider-utils":"2.1.11","google-auth-library":"^9.15.0"},"devDependencies":{"@types/node":"^18","tsup":"^8","typescript":"5.6.3","zod":"3.23.8","@khulnasoft/ai-tsconfig":"0.0.0"},"peerDependencies":{"zod":"^3.0.0"},"engines":{"node":">=18"},"publishConfig":{"access":"public"},"homepage":"https://sdk.khulnasoft.com/docs","repository":{"type":"git","url":"git+https://github.com/khulnasoft/ai-toolkit.git"},"bugs":{"url":"https://github.com/khulnasoft/ai-toolkit/issues"},"keywords":["ai-toolkit"],"scripts":{"build":"tsup","build:watch":"tsup --watch","clean":"rm -rf dist && rm -rf edge/dist && rm -rf anthropic/dist && rm -rf anthropic/edge/dist","lint":"eslint \"./**/*.ts*\"","type-check":"tsc --noEmit","prettier-check":"prettier --check \"./**/*.ts*\"","test":"pnpm test:node && pnpm test:edge","test:edge":"vitest --config vitest.edge.config.js --run","test:node":"vitest --config vitest.node.config.js --run"},"_id":"@ai-toolkit/google-vertex@2.1.24","description":"The **[Google Vertex provider](https://sdk.khulnasoft.com/providers/ai-toolkit-providers/google-vertex)** for the [AI TOOLKIT](https://sdk.khulnasoft.com/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) ","_integrity":"sha512-fHUbdPVqBIQZ6Ta5CCoXMVcz9vEnJdra3x5sRoxdgxiHY+GEHr9jvTjQrO/qp1uG3vc5Xmj+ivXUNhfuaOqGBQ==","_resolved":"/tmp/35c02f2da708e70955fd2ba78390da37/ai-toolkit-google-vertex-2.1.24.tgz","_from":"file:ai-toolkit-google-vertex-2.1.24.tgz","_nodeVersion":"22.13.1","_npmVersion":"10.9.2","dist":{"integrity":"sha512-fHUbdPVqBIQZ6Ta5CCoXMVcz9vEnJdra3x5sRoxdgxiHY+GEHr9jvTjQrO/qp1uG3vc5Xmj+ivXUNhfuaOqGBQ==","shasum":"fa999f9add37648b387d116b52ca0c1b0bf7b2f7","tarball":"https://registry.npmjs.org/@ai-toolkit/google-vertex/-/google-vertex-2.1.24.tgz","fileCount":27,"unpackedSize":236007,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDi29a4jY8KKiGvFqFbQdpy25SBB7dEUVkr2mk3lVi28AIhAIBg18MoR7nX4+y5zbrLKYidqVjcpNAOI1e7ke40u/yU"}]},"_npmUser":{"name":"khulnasoft-lab","email":"iconmamundentist@gmail.com"},"directories":{},"maintainers":[{"name":"khulnasoft-lab","email":"iconmamundentist@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/google-vertex_2.1.24_1741546716729_0.10857175502717564"},"_hasShrinkwrap":false}},"time":{"created":"2025-03-09T18:58:36.607Z","2.1.24":"2025-03-09T18:58:36.900Z","modified":"2025-03-09T18:58:37.222Z"},"maintainers":[{"name":"khulnasoft-lab","email":"iconmamundentist@gmail.com"}],"description":"The **[Google Vertex provider](https://sdk.khulnasoft.com/providers/ai-toolkit-providers/google-vertex)** for the [AI TOOLKIT](https://sdk.khulnasoft.com/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) ","homepage":"https://sdk.khulnasoft.com/docs","keywords":["ai-toolkit"],"repository":{"type":"git","url":"git+https://github.com/khulnasoft/ai-toolkit.git"},"bugs":{"url":"https://github.com/khulnasoft/ai-toolkit/issues"},"license":"Apache-2.0","readme":"# AI TOOLKIT - Google Vertex AI Provider\n\nThe **[Google Vertex provider](https://sdk.khulnasoft.com/providers/ai-toolkit-providers/google-vertex)** for the [AI TOOLKIT](https://sdk.khulnasoft.com/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs.\n\nThis library includes a Google Vertex Anthropic provider. This provider closely follows the core Google Vertex library's usage patterns. See more in the [Google Vertex Anthropic Provider](#google-vertex-anthropic-provider) section below.\n\n## Setup\n\nThe Google Vertex provider is available in the `@ai-toolkit/google-vertex` module. You can install it with\n\n```bash\nnpm i @ai-toolkit/google-vertex\n```\n\n## Google Vertex Provider\n\nThe Google Vertex provider has two different authentication implementations depending on your runtime environment:\n\n### Node.js Runtime\n\nThe Node.js runtime is the default runtime supported by the AI TOOLKIT. You can use the default provider instance to generate text with the `gemini-1.5-flash` model like this:\n\n```ts\nimport { vertex } from '@ai-toolkit/google-vertex';\nimport { generateText } from 'ai-toolkit';\n\nconst { text } = await generateText({\n  model: vertex('gemini-1.5-flash'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\nThis provider supports all standard Google Cloud authentication options through the [`google-auth-library`](https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#ways-to-authenticate). The most common authentication method is to set the path to a json credentials file in the `GOOGLE_APPLICATION_CREDENTIALS` environment variable. Credentials can be obtained from the [Google Cloud Console](https://console.cloud.google.com/apis/credentials).\n\n### Edge Runtime\n\nThe Edge runtime is supported through the `@ai-toolkit/google-vertex/edge` module. Note the additional sub-module path `/edge` required to differentiate the Edge provider from the Node.js provider.\n\nYou can use the default provider instance to generate text with the `gemini-1.5-flash` model like this:\n\n```ts\nimport { vertex } from '@ai-toolkit/google-vertex/edge';\nimport { generateText } from 'ai-toolkit';\n\nconst { text } = await generateText({\n  model: vertex('gemini-1.5-flash'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\nThis method supports Google's [Application Default Credentials](https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#application-default-credentials) through the environment variables `GOOGLE_CLIENT_EMAIL`, `GOOGLE_PRIVATE_KEY`, and (optionally) `GOOGLE_PRIVATE_KEY_ID`. The values can be obtained from a json credentials file obtained from the [Google Cloud Console](https://console.cloud.google.com/apis/credentials).\n\n## Google Vertex Anthropic Provider\n\nThe Google Vertex Anthropic provider is available for both Node.js and Edge runtimes. It follows a similar usage pattern to the [core Google Vertex provider](#google-vertex-provider).\n\n### Node.js Runtime\n\n```ts\nimport { vertexAnthropic } from '@ai-toolkit/google-vertex/anthropic';\nimport { generateText } from 'ai-toolkit';\n\nconst { text } = await generateText({\n  model: vertexAnthropic('claude-3-5-sonnet@20240620'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\n### Edge Runtime\n\n```ts\nimport { vertexAnthropic } from '@ai-toolkit/google-vertex/anthropic/edge';\nimport { generateText } from 'ai-toolkit';\n\nconst { text } = await generateText({\n  model: vertexAnthropic('claude-3-5-sonnet@20240620'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\n## Prompt Caching Support for Anthropic Claude Models\n\nThe Google Vertex Anthropic provider supports prompt caching for Anthropic Claude models. Prompt caching can help reduce latency and costs by reusing cached results for identical requests. Caches are unique to Google Cloud projects and have a five-minute lifetime.\n\n### Enabling Prompt Caching\n\nTo enable prompt caching, you can use the `cacheControl` property in the settings. Here is an example demonstrating how to enable prompt caching:\n\n```ts\nimport { vertexAnthropic } from '@ai-toolkit/google-vertex/anthropic';\nimport { generateText } from 'ai-toolkit';\nimport fs from 'node:fs';\n\nconst errorMessage = fs.readFileSync('data/error-message.txt', 'utf8');\n\nasync function main() {\n  const result = await generateText({\n    model: vertexAnthropic('claude-3-5-sonnet-v2@20241022', {\n      cacheControl: true,\n    }),\n    messages: [\n      {\n        role: 'user',\n        content: [\n          {\n            type: 'text',\n            text: 'You are a JavaScript expert.',\n          },\n          {\n            type: 'text',\n            text: `Error message: ${errorMessage}`,\n            providerOptions: {\n              anthropic: {\n                cacheControl: { type: 'ephemeral' },\n              },\n            },\n          },\n          {\n            type: 'text',\n            text: 'Explain the error message.',\n          },\n        ],\n      },\n    ],\n  });\n\n  console.log(result.text);\n  console.log(result.experimental_providerMetadata?.anthropic);\n  // e.g. { cacheCreationInputTokens: 2118, cacheReadInputTokens: 0 }\n}\n\nmain().catch(console.error);\n```\n\n## Custom Provider Configuration\n\nYou can create a custom provider instance using the `createVertex` function. This allows you to specify additional configuration options. Below is an example with the default Node.js provider which includes a `googleAuthOptions` object.\n\n```ts\nimport { createVertex } from '@ai-toolkit/google-vertex';\nimport { generateText } from 'ai-toolkit';\n\nconst customProvider = createVertex({\n  project: 'your-project-id',\n  location: 'us-central1',\n  googleAuthOptions: {\n    credentials: {\n      client_email: 'your-client-email',\n      private_key: 'your-private-key',\n    },\n  },\n});\n\nconst { text } = await generateText({\n  model: customProvider('gemini-1.5-flash'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\nThe `googleAuthOptions` object is not present in the Edge provider options but custom provider creation is otherwise identical.\n\nThe Edge provider supports a `googleCredentials` option rather than `googleAuthOptions`. This can be used to specify the Google Cloud service account credentials and will take precedence over the environment variables used otherwise.\n\n```ts\nimport { createVertex } from '@ai-toolkit/google-vertex/edge';\nimport { generateText } from 'ai-toolkit';\n\nconst customProvider = createVertex({\n  project: 'your-project-id',\n  location: 'us-central1',\n  googleCredentials: {\n    clientEmail: 'your-client-email',\n    privateKey: 'your-private-key',\n  },\n});\n\nconst { text } = await generateText({\n  model: customProvider('gemini-1.5-flash'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\n### Google Vertex Anthropic Provider Custom Configuration\n\nThe Google Vertex Anthropic provider custom configuration is analogous to the above:\n\n```ts\nimport { createVertexAnthropic } from '@ai-toolkit/google-vertex/anthropic';\nimport { generateText } from 'ai-toolkit';\n\nconst customProvider = createVertexAnthropic({\n  project: 'your-project-id',\n  location: 'us-east5',\n});\n\nconst { text } = await generateText({\n  model: customProvider('claude-3-5-sonnet@20240620'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\nAnd for the Edge runtime:\n\n```ts\nimport { vertexAnthropic } from '@ai-toolkit/google-vertex/anthropic/edge';\nimport { generateText } from 'ai-toolkit';\n\nconst customProvider = createVertexAnthropic({\n  project: 'your-project-id',\n  location: 'us-east5',\n});\n\nconst { text } = await generateText({\n  model: customProvider('claude-3-5-sonnet@20240620'),\n  prompt: 'Write a vegetarian lasagna recipe.',\n});\n```\n\n## Documentation\n\nPlease check out the **[Google Vertex provider](https://sdk.khulnasoft.com/providers/ai-toolkit-providers/google-vertex)** for more information.\n","readmeFilename":"README.md","_rev":"1-41db99a397108a682c4a1c11530fbb07"}