AI

Chat API

The thirdweb AI chat API is a standard OpenAI-compatible chat completion API that allows you to interact with the thirdweb AI model, optimized for blockchain interactions.

  • Query real-time data from the blockchain
  • Analyze transactions
  • Fetch token balances, prices and metadata
  • Prepare any contract call or transaction for signing
  • Prepare swaps from/to any token pair
  • Deploy contracts
  • Generate images
  • Search the web
  • And more!

You can use the API with the HTTP API directly, or with any OpenAI-compatible client library.

Request

fetch("https://api.thirdweb-dev.com/ai/chat", {
method: "POST",
headers: {
"x-secret-key": "<your-project-secret-key>",
},
body: {
messages: [
{
role: "user",
content: "Send 0.01 ETH to vitalik.eth",
},
],
context: {
chain_ids: [8453],
from: "0x1234567890123456789012345678901234567890",
},
stream: false,
},
});

Response

{
"message": "I've prepared a native ETH transfer as requested. Would you like to proceed with executing this transfer?",
"session_id": "123",
"request_id": "456",
"actions": [
{
"type": "sign_transaction",
"data": {
"chainId": 8453,
"to": "0x1234567890123456789012345678901234567890",
"value": "10000000000000000",
"data": "0x"
},
"session_id": "123",
"request_id": "456",
"source": "model",
"tool_name": null,
"description": null,
"kwargs": null
}
]
}

Going further