OpenAI Adapter
Use Commerce Gateway with OpenAI models via function calling and parallel tool calls.
1 min read · LLM Adapters
Installation
npm install @commerce-gateway/sdk openai
OpenAI function calling
OpenAIAdapter maps gateway operations to OpenAI chat-completions tools and executes tool results when finish_reason === "tool_calls".
Basic usage
import { OpenAIAdapter } from "@betterdata/commerce-gateway/openai";
const adapter = new OpenAIAdapter({
apiKey: process.env.OPENAI_API_KEY!,
model: "gpt-4o",
tools: ["search_products", "get_product_details"],
});
const response = await adapter.handleRequest({
messages: [{ role: "user", content: "Find premium trail shoes" }],
});
Parallel tool calls
OpenAI can emit parallel function calls. The adapter consumes the returned tool call array, executes each call, and continues the conversation with tool-role messages.
JSON mode
When needed, pass OpenAI-native options at the model layer (response_format: { type: "json_object" }) in your upstream client orchestration.
Model compatibility
Works with GPT-4o and o-series models that support tool use.
Commerce Registry
For brand and product resolution to gateway endpoints, see the Registry overview and .well-known File (createRegistryClient in @betterdata/commerce-gateway).