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 whosesupported_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
Data Extraction from Text
Data Extraction from Text
Extract structured data from unstructured text:
Form Auto-Fill
Form Auto-Fill
Auto-fill forms from natural language:
API Response Formatting
API Response Formatting
Ensure API responses match your spec:
Database Record Creation
Database Record Creation
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 whosesupported_parameters include response_format or
structured_outputs. Check GET /v1/models.
Performance Tips
- Use
strict: truefor guaranteed schema compliance - Simpler schemas = faster responses
- Provide examples in system message for complex structures
- 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 OpenAItools 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
- Clear descriptions: Help model understand when to call functions
- Type safety: Use strict JSON Schema types or Pydantic models
- Error handling: Validate function arguments with try/except
- Security: Never execute untrusted code from function calls
- Use structured outputs: For guaranteed JSON schema compliance
- TEE for sensitive data: Use confidential (
is_tee) models for PII extraction