Request Parameters and JSON
What Are AdditionalParameters and ExtInfo?
These fields pass model-specific options that cannot be expressed with the base request fields. They are not common aliases; their position and data type differ by API and by model. Check the parameter table of the engine first to see whether the field is an object or a JSON string.
How Is a JSON Object Different from a JSON String?
An object passes keys and values as a structure, while a JSON string holds that structure inside a string. The two values below have different data types. If the documentation requires String, do not pass an object as is.
{"options": {"enabled": true}}{"options": "{\"enabled\":true}"}The name options above is used only to compare data types. In an actual request, use the field name defined in API.
Why Are Backslashes and Quotes Needed in Examples?
Quotes inside a string are written as \", backslashes as \\, and line breaks as \n. This is not a comment but escape notation for JSON. A SDK or JSON serialization function handles the required characters automatically. Do not strip backslashes from the finished request body.
Can I Put // Comments in JSON?
Standard JSON does not allow // or /* ... */ comments. When you send a value that contains explanatory comments, remove the comments and validate the JSON syntax. A https:// inside a string is part of a URL, so do not remove it.
How Many Times Should I Serialize When Building a JSON String?
Keep fields that accept an object as objects. For a field that accepts a JSON string, serialize the inner object once into a string and then place it in the request object. Leave serialization of the HTTP request body to the JSON option of the SDK or HTTP client. Serializing an already serialized string again adds outer quotes, so API may no longer match the expected structure.
How Do I Pass Line Breaks in Lyrics or Prompts?
In your program, build a string that contains the line breaks and use a JSON serialization function. When you write the JSON body by hand, represent line breaks inside the string as \n. For fields with a nested JSON string such as AdditionalParameters, distinguish between the inner and outer serialization.
Should Optional Fields Be Passed as an Empty String or null?
When you do not specify a value, check the default value and the omission rule for that field. Omission, an empty string, and null are different values. Do not insert null or empty values that the documentation does not allow into every optional field.