Skip to main content

Helper for authenticating with VertexAI

Project description

VertexAuth

This is a helper library for accessing Google Vertex AI models

To use it, get a GCloud Service Account Key File (SAKF), then save a default "superkey" file into your .config dir, like so:

from vertexauth import create_superkey_file
path=create_superkey_file(SAKF_path='/path/to/gcloud/service_auth_key_file.json',
                                     region='us-east5',
                                     save_as_default=True)

The superkey file is just the SAKF file with region information added.

Then later, you can create a claudette client or AnthropicVertex client object like so:

from vertexauth import get_anthropic_client, get_claudette_client, load_vertex_vals
from claudette import Chat

# AnthropicVertex
anthropic_client = get_anthropic_client()

# claudette.Client
claudette_client = get_claudette_client()
cl_chat = Chat(cli=claudette_client)
cl_chat("Hi, there!")

# just read the vals
val_dict = load_vertex_vals()

These functions also let you pass a path to a specific superkey, instad of loading the default one.

Alternatively, they can read an env var, VERTEXAUTH_SUPERKEY, which contains a superkey as a string. This lets you share it and use it like a normal API key. However, it's a bit long -- around 2,500 characters, since it's simply the gzipped, base64-encoded contents of the file. Use create_superkey_env_value to create one.

Huh, what's a Service Account Key File?

Yes it would be easier of course if Google just gave us a single API key value. But they don't.

afaict the closest you can get to this with Google Vertex AI is to generate a "Service Account Key File" (SAKF), a JSON file with embedded credentials. But even once you have this, you need to supply it along with other coordinated pieces of information (like project ID and region) in order to make an API request against a VertexAI model. So it's a bit of a hassle., and that's what this library helps with. That's all.

But how do I get this blessed Service Account Key File from Google

It's not pretty. Here's approximately what you need to do:

  • Go to Google Cloud console
  • Select a project
  • Go to APIs & Services
  • Go to Enabled APIs and Services
  • Select "Vertex AI API" from the list and ensure that it is Enabled"
  • Within that panel, select "Quotas and System Limits"
    • In the filter control, enter the property name "Online prediction requests per base model per minute per region per base_model" to find that row.
    • Scope to a particular region (e.g., "us-east5") and and base_model (e.g., "anthropic-claude-3-5-sonnet-v2")
    • Use "Edit Quota" to ensure that you have a non-zero quote for it
  • Also, within that same panel, select "Credentials"
    • Click "+ Create Credentials"
    • Select "Service Account"
    • Enter a name like "vertexaiserviceaccount" etc for the account,
    • For permissions, give it the "Vertex AI Service Agent" role.
    • Go to keys, select "Add key" and select "JSON"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vertexauth-0.1.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vertexauth-0.1.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file vertexauth-0.1.1.tar.gz.

File metadata

  • Download URL: vertexauth-0.1.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Darwin/23.6.0

File hashes

Hashes for vertexauth-0.1.1.tar.gz
Algorithm Hash digest
SHA256 89f0d8f36e10d468af939d1f2d1132d033fc10fa85145844ee425be342c2bf46
MD5 6a0b378b844ad1b0197bd824c0eb11e6
BLAKE2b-256 ac517b477f646b29351ffbff463089c0f80a8cce3996adfc961678c2dcd7ff63

See more details on using hashes here.

File details

Details for the file vertexauth-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: vertexauth-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Darwin/23.6.0

File hashes

Hashes for vertexauth-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4431912ab5487714e2a3bad061b04537ae2c573a8b038d150bc5cbc798f5eb2e
MD5 d8c122970ca9b78a66d247fd32521482
BLAKE2b-256 60fe474b5983dc48e94acc626601207ee0127c0a2e7d81b5e7decb79c1f91a4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page