https://www.boundaryml.com logo
๐ŸŸก Query about passing a key in vertex-ai
# questions
t
I am trying to use vertex-ai and pass it a key (which in theory it supports as a query string variable). But I can't get BAML to want to do it. Any ideas?
v
We do technically support query parameters. Let me look at the code. I donโ€™t think we document it.
t
you figure it out?
I looked at
RequestBuilder for VertexClient
and didnt see it right away but you know i dunno rust for shit
v
oops! sorry forgot to update. we have query params for only openai
t
yeah
v
i'll put cursor agent on it
t
soooooo, key as a query string param is a valid thing
v
yea let me look into it
any reason you can't use the api key as a header btw?
t
yes, vertex doesnt support it
it supports that insanely awful gcp auth bullshit
v
๐Ÿ˜ฎ
oh got it
t
which i could switch to
v
yep will solve
t
but id prefer not to
my plan from my read is to use proxy_url in the short term
im missing where this is
t
its on the query string not hte request body
lemme find it
could be ai hallucination but i saw it somewhere
curl -X POST -H "Content-Type: application/json" "https://${API_ENDPOINT}/v1/publishers/google/models/${MODEL_ID}:${GENERATE_CONTENT_API}?key=${API_KEY}" -d $'{ "contents": { "role": "user", "parts": { "text": "Explain how AI works in a few words" } } }'
whew
DIDNT HALLUCINATE IT
ugh, how would i get the key into the proxy url?
v
Ok Iโ€™ll find a way to get this. I think it works via client registry but need to test.
@aaronv (BAML) can you help Todd here?
a
Yep ill take a look today
t
Can I do string concat in the clients baml file?
If so I can probably skip client builder
a
@Antonio Sarosi (BAML ๐Ÿ‘) is string concat possible now here?
Can you show me the part you wanna string concat?
t
I want to concat the proxy url so I can inject the env key into the url
I can also use client builder if thatโ€™s supported in go
But string concat seemed easier if it works
a
ok looking at it now, we do this in openai IIRC so i can patch this
t
oh, damn, @Vaibhav (BAML ๐Ÿ‘) proxy url wont work
because its trying to call some local gcloud bullshit
I setup the registry like
Copy code
registry := baml.ClientRegistry{}
        registry.AddLlmClient("Gemini", "vertex-ai", map[string]any{
            "location":   "global",
            "project_id": "grand-pact-470219-h2",
            "model":      "gemini-2.5-flash",
            "proxy_url":  fmt.Sprintf("https://aiplatform.googleapis.com/v1/projects/grand-pact-470219-h2/locations/global/publishers/google/models/gemini-2.5-flash:generateContent?key=%s", os.Getenv("GEMINI_API_KEY")),
        })
        registry.SetPrimaryClient("Gemini")
and it spits out some
Copy code
[2025-09-24T19:19:57Z ERROR baml_runtime::internal::llm_client::primitive::vertex::std_auth] Failed to auth using GcloudApplicationDefaultCredentials strategy

    Caused by:
        token request failed
[2025-09-24T19:19:57Z ERROR baml_runtime::internal::llm_client::primitive::vertex::std_auth] Failed to auth using MetadataServiceAccount strategy

    Caused by:
        0: HTTP request failed: client error (Connect)
        1: client error (Connect)
        2: dns error
        3: failed to lookup address information: nodename nor servname provided, or not known
[2025-09-24T19:19:57Z ERROR baml_runtime::internal::llm_client::primitive::vertex::std_auth] Failed to auth using GCloudAuthorizedUser strategy

    Caused by:
        running `gcloud` command failed
Which is curious because before it was making the call and failing
oh that url is drunk talk
fucking bad paste
oh wait, it was fine
a
i think it's just a diff way to override, give me a few min
t
๐Ÿ‘
a
ah yeah in openai we have a thing called
Copy code
client LLM {
 options {
    query_params ".."
    headers "..."
 }
}
so i just need to wire it in for vertex
patch is gonna go out. So youll be able to do:
Copy code
client LLM {
 options {
    query_params {
      key env.YourKEY
    }
 }
}
PR almost out, just doing final test
t
oh thatll be awesome
will you do a release with that or am i waiting until next week to be able to use it?
a
Illl do it now
So eta like 2 hrs
t
nice thanks!
a
PR queued to merge: https://github.com/BoundaryML/baml/pull/2512 (10min), then final test (10min), then release (35min). will ping here when it's done
t
Thanks!
Holy shit lots of lines of code changed Batman
a
it's 99% generated files
we probably have to start ignoring these
fyi it probably won't work on the BAML Playground, but it worked on my actual TS / Python code
t
awesome, i probably wont test it until tmw, sucked into some other shit
a
sounds good
i have an additional fix for the playground -- though it shouldn't affect your code. It just makes it so we dont do the whole gcloud auth dance at all if the api key is set https://github.com/BoundaryML/baml/pull/2516 . I'll release this as 0.208.5. Whenever you get a chance try 0.208.4 (already out) or .5 if it's available
t
nice, thanks!
oof
Copy code
FFI function error: Failed to create BAML runtime: error: Error validating field `float` in class `float`: Field name cannot be a BAML language keyword.
๐Ÿ˜‰
v
Use alias ๐Ÿ™‚
a
myFloat: string @alias("float")
v
No colons ๐Ÿฅฒ
t
oh, i changed it to
isFloat
which is fine
yall just out here ruining my good time
it should be isFloat anyway cause it was a boolean
also A+ change on unions to do AsWhatever() instead of Whatever()
reads much nicer
v
๐Ÿ™‚
FYI we may end up reserving a few more keywords coming up soon! (Some really exciting stuff is coming up ๐Ÿ™‚ )
t
ok, im getting a weird error now
suggesting that its calling the prediction service
not the publisher model
Copy code
client<llm> Gemini {
  provider vertex-ai
  options {
    location "global"
    project_id "grand-pact-470219-h2"
    model "gemini-2.5-flash"
    query_params {
      key env.GEMINI_API_KEY
    }
  }
  retry_policy Exponential
}
thats my client definition
and unfortunately the actual url is never logged?
a
the playground shows the curl -- what does that return?
t
lemme try
a
on 0.208.5 of the extension
t
nope
oh maybe an old extension
lemme update
yah, curl fails the same way
I get back
Copy code
{
  "error": {
    "code": 401,
    "message": "API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See https://cloud.google.com/docs/authentication",
    "status": "UNAUTHENTICATED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "CREDENTIALS_MISSING",
        "domain": "googleapis.com",
        "metadata": {
          "method": "google.cloud.aiplatform.v1.PredictionService.GenerateContent",
          "service": "aiplatform.googleapis.com"
        }
      }
    ]
  }
}
a
did you enable vertex api keys? one sec
t
yes i believe the api key i have is valid
but clearly it isnt somehow ๐Ÿ˜‰
let me try using
global
as the location as well on my end
t
yah, ive done that, you cant get one without doing so
a
ok let me see why mine works, one sec
god i hate vertex
t
ah fuck
thats why according to chatgpt
Copy code
You hit the right REST method, but two things in your cURL make Vertex AI treat it like an OAuth-only call:

Youโ€™re calling the global location.

Youโ€™re using the non-regional host (aiplatform.googleapis.com) with an API key.

With Vertex AI, API-key auth works on the publisher endpoints when you call a region (for example us-central1) and include the key (header or ?key=). Using global generally assumes OAuth/ADC. 
Google Cloud
+2
Google Cloud
+2

Try either of these (pick a region your model supports, e.g. us-central1):
a
ah, my client is:
Copy code
client<llm> VertexWithQueryParams {
  provider vertex-ai
  options {
    model gemini-2.5-flash
    location us-central1
    project_id "gloo-ai"
    query_params {
      key env.VERTEX_API_KEY
    }
  }
}
btw api keys have much lower rate limits no? not sure what the diff is here other than its easier to use them
t
oh fuck me
does it want the wrong project_id
do they have lower rate limits?
yeah none of these things change the autocome for me
i gotta shower and head into the office
ill look at it once i get there
can i pass in a json credentials blob to baml instead?
the answer may be just to do that
i dont want to fuck with the gcloud cli at all in production
a
yes definitely
just set the GOOGLE_APPLICATION_DEFAULT_CREDENTIALS, and dont use an api key
t
hrm ok
ill look into that!
fuckin hate google
you have no idea how hard it was to get GCP credits from these idiots
probably burned 10K on anthropic waiting
fucking morons
a
example with credentials:
Copy code
client<llm> VertexClaude {
  provider vertex-ai
  options {
    model "claude-3-5-sonnet@20240620"
    location us-east5
    anthropic_version "vertex-2023-10-16"
    credentials env.INTEG_TESTS_GOOGLE_APPLICATION_CREDENTIALS_CONTENT
  }
}
Where: the env var is a json blob: https://cdn.discordapp.com/attachments/1420216485581820007/1420831203774173257/image.png?ex=68d6d3ac&is=68d5822c&hm=bbd431e8166ce37cc2cc5bd2b6fb86ae9379089d781fb81ec9d1d5576f19dbe8&
i believe that haha
it's just gemini has literally 10 diff docs on how to do the same thing
it's insane
For vertex api key, this one also worked for me, using global location and project id on extension 0.208.5
Copy code
client<llm> VertexWithQueryParams {
  provider vertex-ai
  options {
    model gemini-2.5-flash
    location global
    project_id "gloo-ai"
    query_params {
      key env.VERTEX_API_KEY
    }
  }
}
Copy code
curl -X POST 'https://aiplatform.googleapis.com/v1/projects/gloo-ai/locations/global/publishers/google/models/gemini-2.5-flash:generateContent?key=xyz' -H "content-type: application/json" -d "{
  \"contents\": [
    {
      \"role\": \"user\",
      \"parts\": [
        {
          \"text\": \"Write a nice story.\"
        }
      ]
    }
  ]
}"
Something tells me there's something you need to enable on your account
check out the diff here -- it seems your account does need something enabled properly (like the enforcement thing in the screenshot i posted) https://github.com/google-gemini/gemini-cli/pull/6193/files
t
ok lemme check it out
a
t
got it working
i hate myself
i feel disgusting
but its done
a
What was the issue? XD
So i can potentially update docs
t
I just switched to long lived service account keys which it is now yelling at me for doing because itโ€™s insecure but thatโ€™s fine