Skip to content

Grouding on gemini 2 REST API #1643

Description

@jbg469

Discussed in #1642

Originally posted by jbg469 January 21, 2025
I manage to curl a reply as so here

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=KEY" \
  -H 'Content-Type: application/json' \
  -X POST \
  -d '{
    "contents": [{
      "parts":[{"text": "Write a story about a magic backpack."}]
    }]
  }'
  
  -----
  this works for gemini 1.5
  
  echo '{"contents":
          [{"parts": [{"text": "What is the current Google stock price?"}]}],
      "tools": [{"google_search_retrieval": {
                  "dynamic_retrieval_config": {
                    "mode": "MODE_DYNAMIC",
                    "dynamic_threshold": 1,
                }
            }
        }
    ]
}' > request.json

curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-002:generateContent?key=KEY" \
-H "Content-Type: application/json" \
-d  @request.json > response.json

cat response.json

---- however with gemini 2.0 :

echo '{"contents":
          [{"parts": [{"text": "What is the current Google stock price?"}]}],
      "tools": [{"google_search": {
                  "dynamic_retrieval_config": {
                    "mode": "MODE_DYNAMIC",
                    "dynamic_threshold": 1,
                }
            }
        }
    ]
}' > request.json

curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=KEY" \
-H "Content-Type: application/json" \
-d  @request.json > response.json

cat response.json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   874    0   572  100   302   1568    828 --:--:-- --:--:-- --:--:--  2394
{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"dynamic_retrieval_config\" at 'tools[0].google_search': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "tools[0].google_search",
            "description": "Invalid JSON payload received. Unknown name \"dynamic_retrieval_config\" at 'tools[0].google_search': Cannot find field."
          }
        ]
      }
    ]
  }
}

I can't seem to find relevant docs on the REST API I am constrained to this version and can't use the python library at the moment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions