Welcome to Portkey Forum

Updated 2 days ago

Troubleshooting Format Errors When Using OpenAI and Google APIs

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
}
s
k
6 comments
Hey @kam are you sending your schema in function.parameters.schema or function.parameters, the latter is the correct way to send it, example:
Plain Text
        {
            "type": "function",
            "function": {
                "strict": true,
                "name": "get_current_temperature",
                "description": "Get the current temperature for a specific location",
                "parameters": {
                    "type": "object",
                    "properties": {
                        "additional_properties": true,
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g., San Francisco, CA"
                        },
                        "unit": {
                            "type": "string",
                            "enum": [
                                "Celsius",
                                "Fahrenheit"
                            ],
                            "description": "The temperature unit to use. Infer this from the user's location."
                        }
                    },
                    "required": [
                        "location",
                        "unit"
                    ]
                }
            }
        }
if you're trying to specify response_format, you should use the response_format key instead
openai is a little bit flexible with their implementation that is why it might be working for you, but you should be using it this way
I'm using the function.parameters key as you suggest, see snippet. Google seems to have a different payload format for tool calling, requiring contents instead of messages Am I reading there docs right? https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/function-calling#examples

Plain Text
  "tools": [{
      "type": "function",
      "function": {
        "name": "searchGoogle",
        "parameters": {
          "type": "object",
          "properties": {
            "query": {
              "type": "string",
              ...
Or do I need to direct portkey to hit a different route to make the call OpenAI sdk compliant? https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-vertex-using-openai-library
You don’t need to transform the payload to Google api signature yourself, the gateway handles it for you
Add a reply
Sign up and join the conversation on Discord