Hi, guys! I'm trying to use Ai Gateway to cache requests for Gemini using Google Ai Studio but maybe

Hi, guys! I'm trying to use Ai Gateway to cache requests for Gemini using Google Ai Studio but maybe i am doing something wrong :/ I am getting some errors regarding the system_instruction and generationConfig parameters The same request works by using the direct endpoint on google https://generativelanguage.googleapis.com/v1beta/models/
400 Bad Request: "{<EOL> "error": {<EOL> "code": 400,<EOL> "message": "Invalid JSON payload received. Unknown name \"system_instruction\": Cannot find field.\nInvalid JSON payload received. Unknown name \"response_mime_type\" at 'generation_config': Cannot find field.",<EOL> "status": "INVALID_ARGUMENT",<EOL> "details": [<EOL> {<EOL> "@type": "type.googleapis.com/google.rpc.BadRequest",<EOL> "fieldViolations": [<EOL> {<EOL> "description": "Invalid JSON payload received. Unknown name \"system_instruction\": Cannot find field."<EOL> },<EOL> {<EOL> "field": "generation_config",<EOL> "description": "Invalid JSON payload received. Unknown name \"response_mime_type\" at 'generation_config': Cannot find field."<EOL> }<EOL> ]<EOL> }<EOL> ]<EOL> }<EOL>}<EOL>"
400 Bad Request: "{<EOL> "error": {<EOL> "code": 400,<EOL> "message": "Invalid JSON payload received. Unknown name \"system_instruction\": Cannot find field.\nInvalid JSON payload received. Unknown name \"response_mime_type\" at 'generation_config': Cannot find field.",<EOL> "status": "INVALID_ARGUMENT",<EOL> "details": [<EOL> {<EOL> "@type": "type.googleapis.com/google.rpc.BadRequest",<EOL> "fieldViolations": [<EOL> {<EOL> "description": "Invalid JSON payload received. Unknown name \"system_instruction\": Cannot find field."<EOL> },<EOL> {<EOL> "field": "generation_config",<EOL> "description": "Invalid JSON payload received. Unknown name \"response_mime_type\" at 'generation_config': Cannot find field."<EOL> }<EOL> ]<EOL> }<EOL> ]<EOL> }<EOL>}<EOL>"
9 Replies
nicolasmnl
nicolasmnlOP4mo ago
Example of request made:
{
"system_instruction": {
"parts": {"text": "You are a chatbot."}},
"contents": [{
"role":"user",
"parts":[{
"text": "Hello!"}]}
],
"generationConfig": {
"maxOutputTokens": 2048,
"temperature": 1.0,
"response_mime_type": "application/json"
}
}
{
"system_instruction": {
"parts": {"text": "You are a chatbot."}},
"contents": [{
"role":"user",
"parts":[{
"text": "Hello!"}]}
],
"generationConfig": {
"maxOutputTokens": 2048,
"temperature": 1.0,
"response_mime_type": "application/json"
}
}
Am i doing something wrong? Or since it is on beta, somethings are still yet to be implemented?
horrible
horrible4mo ago
json is camel cased within googleapis change system_instruction to systemInstruction and response_mime_type to responseMimeType
nicolasmnl
nicolasmnlOP4mo ago
Hummm 🤔 Saw this example within Google APIs
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY \
-H 'Content-Type: application/json' \
-d '{ "system_instruction": {
"parts":
{ "text": "You are Neko the cat respond like one"}},
"contents": {
"parts": {
"text": "Good morning! How are you?"}}}'
curl https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=$GOOGLE_API_KEY \
-H 'Content-Type: application/json' \
-d '{ "system_instruction": {
"parts":
{ "text": "You are Neko the cat respond like one"}},
"contents": {
"parts": {
"text": "Good morning! How are you?"}}}'
Forgot to send the link (sorry 😅 ) https://ai.google.dev/gemini-api/docs/system-instructions?lang=rest
horrible
horrible4mo ago
try it with camel case likely the json to grpc transcoder accepts non-camel case, but not cases where some json keys are camel case while others aren't (such as in your code above) in googleapis, all json/protojson requests are transcoded to grpc calls to google's actual servers they are mapped to a protobuf definition
nicolasmnl
nicolasmnlOP4mo ago
I tried, but got the same error :/
[{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field.\nInvalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field."
},
{
"field": "generation_config",
"description": "Invalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field."
}
]
}
]
}
}
]
[{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field.\nInvalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field."
},
{
"field": "generation_config",
"description": "Invalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field."
}
]
}
]
}
}
]
Thank you for the suggestion anyway!!
Isaac McFadyen
Isaac McFadyen4mo ago
Are you specifying generationConfig or generation_config? It has to all be camel case or all snake case, not a mixture as it seems you might have there. So:
{
"system_instruction":{
"parts":{
"text":"You are a chatbot."
}
},
"contents":[
{
"role":"user",
"parts":[
{
"text":"Hello!"
}
]
}
],
"generation_config":{
"max_output_tokens":2048,
"temperature":1.0,
"response_mime_type":"application/json"
}
}
{
"system_instruction":{
"parts":{
"text":"You are a chatbot."
}
},
"contents":[
{
"role":"user",
"parts":[
{
"text":"Hello!"
}
]
}
],
"generation_config":{
"max_output_tokens":2048,
"temperature":1.0,
"response_mime_type":"application/json"
}
}
Or
{
"systemInstruction":{
"parts":{
"text":"You are a chatbot."
}
},
"contents":[
{
"role":"user",
"parts":[
{
"text":"Hello!"
}
]
}
],
"generationConfig":{
"maxOutputTokens":2048,
"temperature":1.0,
"responseMimeType":"application/json"
}
}
{
"systemInstruction":{
"parts":{
"text":"You are a chatbot."
}
},
"contents":[
{
"role":"user",
"parts":[
{
"text":"Hello!"
}
]
}
],
"generationConfig":{
"maxOutputTokens":2048,
"temperature":1.0,
"responseMimeType":"application/json"
}
}
nicolasmnl
nicolasmnlOP4mo ago
I just tried both, and got the same error Tried with all camelCase like this:
{"contents":[
{
"parts":[
{"text":"Testing"}
],
"role":"user"
}
],
"systemInstruction":{
"parts":{"text”:”Example system"}},
"generationConfig":{"temperature":0.2,"maxOutputTokens":1024,"responseMimeType": "application/json"}}
{"contents":[
{
"parts":[
{"text":"Testing"}
],
"role":"user"
}
],
"systemInstruction":{
"parts":{"text”:”Example system"}},
"generationConfig":{"temperature":0.2,"maxOutputTokens":1024,"responseMimeType": "application/json"}}
And got the same error 🤔
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field.\nInvalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field."
},
{
"field": "generation_config",
"description": "Invalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field."
}
]
}
]
}
}
]
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field.\nInvalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"systemInstruction\": Cannot find field."
},
{
"field": "generation_config",
"description": "Invalid JSON payload received. Unknown name \"responseMimeType\" at 'generation_config': Cannot find field."
}
]
}
]
}
}
]
Funny how in the error message seems like i am sending generation_config, but i am actually sending in camelCase like generationConfig Not sure why
Alex.
Alex.4mo ago
How I change Change My Website FIles In Workers And Pages ANY ONE KNOW
Damien
Damien4mo ago
Hey team. Is it possible to have own inferring server (With OpenAI compatible API) to be proxied by the AI Gateway?
Want results from more Discord servers?
Add your server