Welcome to Portkey Forum

k
kam
Offline, last seen 2 days ago
Joined February 13, 2025
I am using the OpenAI sdk to enable usage of new models/providers but using existing code. Here is a sample JSON object submitted to openai.chat.completions.create(obj) . The code works against OpenAI but I am getting format errors from Google. First I had to remove the $schema key from each tool function.parameters.$schema

I was under the impression that Portkey was suppose to translate the payload formats? Am I doing something wrong?

Current error: BadRequestError: 400 google error: * GenerateContentRequest.contents: contents is not specified

Plain Text
obj = {
  "messages": [
    {
      "role": "developer",
      "content": "I want to buy a hoodie with a fur lined hood. It needs a full zipper. Near Times Square in NYC. Where can I buy one today at lunch time?"
    }
  ],
  "model": "gemini-2.0-flash-001",
  "tool_choice": "auto",
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "searchGoogle",
        "parameters": {
          "type": "object",
          "properties": {
            "query": {
              "type": "string",
              "description": "The search query to send to google."
            }
          },
          "required": [
            "query"
          ],
          "additionalProperties": false
        },
        "strict": true,
        "description": "Run a search query against google for information from the web."
      }
    }
  ],
  "store": false
}
6 comments
s
k
I am experimenting with using the OpenAI sdk (since we have other tooling that relies on it) but using portkey to access other models. Specifically for Google I would have expected the following code to work, but instead of working with the virtual key, I need to specify the actual API key for Google. Am I doing something wrong? Do virtual keys only work with the Portkey sdk?

This fails with BadRequestError: 400 google error: API key not valid. Please pass a valid API key.
Plain Text
const openai = new OpenAI({
  apiKey: process.env["GOOGLE_VIRTUAL_API_KEY"],
  baseURL: PORTKEY_GATEWAY_URL,
  defaultHeaders: createHeaders({
    provider: "google",
    apiKey: process.env["PORTKEY_API_KEY"],
  })
});


If I switch out the GOOGLE_VIRTUAL_API_KEY env var instead for GOOGLE_API_KEY it works.
4 comments
W
C
k