Overview
OpenAI uses “Function Calling” to allow the model to interact with external APIs. The gateway automatically converts your Zod-based tool definitions into the JSON Schema format that OpenAI expects.Usage with OpenAI SDK
1. Setup the OpenAI Adapter
2. Generate Tool Definitions
Pass the generated tools to the OpenAI chat completions API:3. Handle Tool Calls
When the model decides to call a tool, use the gateway to execute it and return the result:Creating a Custom GPT
If you want to create a “Store Assistant” GPT on the OpenAI Store:- Deploy your LLM Gateway to a public URL (e.g., using Vercel).
- In the GPT Editor, go to Actions -> Create new action.
- Import the OpenAPI schema generated by the gateway at
https://your-gateway.com/openapi.json. - Configure your API key for authentication.
Best Practices
- Model Selection: Use
gpt-4-turboor newer for the most reliable tool calling. - System Prompt: Give the model clear instructions on when and how to use the commerce tools.
- Error Handling: OpenAI is sensitive to malformed tool responses. The gateway handles this by always returning structured JSON even on failure.