Jorge
04/03/2025, 10:30 AMVapi Support Bot
04/03/2025, 10:32 AManyOf construct in VAPI, but I couldn't find a definitive solution in our documentation. Based on the error message, it seems VAPI might not fully support the anyOf construct in the same way OpenAI does.
I found that VAPI has its own schema format that adapts to different models like OpenAI and Anthropic, which might explain the incompatibility you're experiencing. According to some information I found, "We have developed our own schema and format for the tools, as Anthropic has different chat completion models that operate according to their specifications, and similarly for OpenAI" [from Discord discussions](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1332510949940133960).
I've escalated your query to our technical team for a definitive answer and possible workaround. They'll be able to provide specific guidance on how to handle nullable optional fields in VAPI's JSON schema implementation.
In the meantime, you might want to try using a simpler schema structure without anyOf if possible, or check if using the strict parameter when creating OpenAI functions in VAPI helps (mentioned in our [changelog](https://docs.vapi.ai/changelog/2024/10/7)).
Someone from our team will get back to you soon with more specific help! 👍Jorge
04/03/2025, 10:32 AMJorge
04/03/2025, 10:36 AMJorge
04/03/2025, 11:03 AMJorge
04/04/2025, 1:56 PMKyle
04/06/2025, 11:48 AMKyle
04/06/2025, 11:54 AMJorge
04/16/2025, 10:36 PMKyle
04/21/2025, 7:29 PMShubham Bajaj
04/22/2025, 4:59 PMShubham Bajaj
04/22/2025, 4:59 PMts
function mapAnyOfWithNullToOptionalParameters(schema: any): any {
// Handle direct anyOf at current level
if (schema.anyOf) {
const nonNullSchema = schema.anyOf.find((item: any) => item.type !== 'null');
return mapAnyOfWithNullToOptionalParameters(nonNullSchema || {});
}
// Process object properties
if (schema.type === 'object' && schema.properties) {
const newOptionalProperties: string[] = [];
const processedProperties = Object.fromEntries(
Object.entries(schema.properties).map(([key, value]) => {
if (typeof value === 'object' && value && 'anyOf' in value) {
newOptionalProperties.push(key);
}
return [key, mapAnyOfWithNullToOptionalParameters(value)];
})
);
return {
...schema,
properties: processedProperties,
required: schema.required?.filter((key: string) => !newOptionalProperties.includes(key)) || [],
};
}
// Process array items
if (schema.type === 'array' && schema.items) {
return {
...schema,
items: mapAnyOfWithNullToOptionalParameters(schema.items),
};
}
return schema;
}Shubham Bajaj
04/22/2025, 4:59 PMts
async function callVAPIWithSchema(schema) {
const vapiCompatibleSchema = mapAnyOfWithNullToOptionalParameters(schema);
// Use vapiCompatibleSchema with VAPI
}Shubham Bajaj
04/22/2025, 5:01 PMShubham Bajaj
04/22/2025, 5:03 PM