Skip to main content

Overview

Function calling allows models to intelligently call functions you define, enabling:
  • API integrations
  • Database queries
  • External tool use
  • Structured data extraction

Define Functions

Complete Example

Supported models

Function calling works on any model whose supported_parameters include tools. Check a model’s supported_parameters in GET /v1/models before relying on it.

Structured Outputs

Structured outputs guarantee that model responses match your exact JSON schema - perfect for data extraction, form filling, and API responses.

Using Pydantic Models

JSON Schema Approach

Complex Nested Structures

Use Cases

Extract structured data from unstructured text:
Auto-fill forms from natural language:
Ensure API responses match your spec:
Generate database-ready records:

Structured Outputs + TEE Privacy

Privacy benefits with the platform:

Validation & Error Handling

Which models support structured outputs

Structured outputs work on models whose supported_parameters include response_format or structured_outputs. Check GET /v1/models.
For models without native structured output support, use function calling with a single function whose parameters match your desired schema.

Performance Tips

  1. Use strict: true for guaranteed schema compliance
  2. Simpler schemas = faster responses
  3. Provide examples in system message for complex structures
  4. Cache Pydantic models for repeated use

Model Context Protocol (MCP)

MCP clients work with this API out of the box. Convert each MCP tool definition to an OpenAI tools entry (the MCP name, description, and inputSchema map directly to function.name, function.description, and function.parameters), send the request, and execute the returned tool_calls against your MCP server. No special endpoint is required: MCP runs on the standard tool-calling shown above.

Best Practices

  1. Clear descriptions: Help model understand when to call functions
  2. Type safety: Use strict JSON Schema types or Pydantic models
  3. Error handling: Validate function arguments with try/except
  4. Security: Never execute untrusted code from function calls
  5. Use structured outputs: For guaranteed JSON schema compliance
  6. TEE for sensitive data: Use confidential (is_tee) models for PII extraction
Always validate and sanitize function arguments before execution. Even with structured outputs, implement defensive programming.