Function & Tool Calling

Define tools (functions) that the model can invoke, then handle the results. CloudVera proxies tool calls transparently — works with OpenAI, Anthropic, Google, Mistral, and any provider that supports function calling.

Features

Provider-Agnostic

Define tools once in OpenAI format. CloudVera translates to each provider's native format — Google's functionDeclarations, Anthropic's tool_use blocks, etc.

Streaming Tool Calls

Tool calls work with streaming too. CloudVera buffers tool call deltas and emits them as complete tool_calls when ready.

Security Scanning

Tool call arguments and results pass through the same security pipeline. Injection attempts in tool responses are detected and blocked.

Code Examples

Define tools and handle calls (Node.js)

const tools = [
  {
    type: 'function' as const,
    function: {
      name: 'get_weather',
      description: 'Get the current weather for a city',
      parameters: {
        type: 'object',
        properties: {
          city: { type: 'string', description: 'City name' },
        },
        required: ['city'],
      },
    },
  },
];

// Step 1: Send request with tools
const response = await openai.chat.completions.create({
  model: 'gpt-4o',
  messages: [{ role: 'user', content: 'What is the weather in Paris?' }],
  tools,
});

const message = response.choices[0].message;

// Step 2: Handle tool calls
if (message.tool_calls) {
  const toolCall = message.tool_calls[0];
  const args = JSON.parse(toolCall.function.arguments);

  // Call your actual function
  const weather = await getWeather(args.city);

  // Step 3: Send tool result back
  const finalResponse = await openai.chat.completions.create({
    model: 'gpt-4o',
    messages: [
      { role: 'user', content: 'What is the weather in Paris?' },
      message,
      { role: 'tool', tool_call_id: toolCall.id, content: JSON.stringify(weather) },
    ],
    tools,
  });

  console.log(finalResponse.choices[0].message.content);
}