I’m trying to use Generative Language API (Gemini API) in my React Native so I’m first trying with a curl. Someone gave me this command :
`
API_KEY="YOUR_API_KEY"
# Adjust safety settings in generationConfig below.
# See https://ai.google.dev/gemini-api/docs/safety-settings
curl
-X POST https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=${API_KEY}
-H 'Content-Type: application/json'
-d @<(echo '{
"contents": [
{
"role": "user",
"parts": [
{
"text": "input: "
},
{
"text": "output: "
}
]
}
],
"generationConfig": {
"temperature": 1,
"topK": 64,
"topP": 0.95,
"maxOutputTokens": 8192,
"responseMimeType": "text/plain"
}
}')
`
But I got this error :
"error": { "code": 400, "message": "Invalid JSON payload received. Unknown name "generationConfig": Cannot find field.", "status": "INVALID_ARGUMENT", "details": [ { "@type": "type.googleapis.com/google.rpc.BadRequest", "fieldViolations": [ { "description": "Invalid JSON payload received. Unknown name "generationConfig": Cannot find field." } ] } ] } }'
Is there something other than the API key to adjust ? I’m trying to use Generative Language API (Gemini API) in my React Native so I’m first trying with a curl. I’d like to have an response from the AI.
2
Answers
The command you used worked fine for me, and it looks like it should work.
I also tried tweaking the
max_output_tokens
field (down to 128) and that worked, giving me a shorter response.Double-check that you are entering the command in correctly. And maybe provide some more info on what you did (e.g. is this in bash? on a mac? windows? powershell? these kinds of changes might impact how the command is interpreted). I successfully ran the command from bash on a linux machine.
It would be easier and better to convert the сURL and use Axios or Fetch:
Using Axios:
npm install axios
Using standart Fetch: