GuidesOpenAI Function Calling

OpenAI Function Calling

Use y0 with OpenAI GPT models via function calling.

Overview

While y0’s primary protocol is MCP, you can also use the tools via OpenAI’s function calling format. The y0 JS SDK provides adapters for this.

Using with OpenAI SDK (Coming Soon)

import OpenAI from 'openai'
import { y0Tools } from '@y0exchange/sdk-js/openai'
 
const openai = new OpenAI()
 
const response = await openai.chat.completions.create({
  model: 'gpt-4',
  messages: [
    { role: 'user', content: 'What is the ETH balance of 0xd8dA...?' }
  ],
  tools: y0Tools,
})

Tool Definitions

The y0 tools map directly to OpenAI function calling format:

{
  "type": "function",
  "function": {
    "name": "get_balance",
    "description": "Get native and ERC-20 token balances for a wallet address",
    "parameters": {
      "type": "object",
      "properties": {
        "address": {
          "type": "string",
          "description": "Wallet address (0x...)"
        },
        "chainId": {
          "type": "number",
          "description": "Chain ID (default: 1)"
        }
      },
      "required": ["address"]
    }
  }
}

Notes

  • The JS SDK (@y0exchange/sdk-js) will provide pre-built OpenAI tool definitions
  • Write tools work the same way — they build unsigned transactions for user signing
  • The signing flow is identical regardless of the AI framework used