---
title: "Chat"
method: POST
path: "/ai/chat"
tags: ["AI"]
---

# Chat

`POST /ai/chat`

Thirdweb AI chat completion API (BETA).

Send natural language queries to interact with any EVM chain, read data, prepare transactions, swap tokens, deploy contracts, payments and more.

Compatible with standard OpenAI API chat completion format, can be used raw or with any popular AI library.

**Authentication**: Pass `x-client-id` header for frontend usage from allowlisted origins or `x-secret-key` for backend usage.

## Request body

- object — Chat request
  - `messages` object[], required — Natural language query for the AI assistant
    - `role` 'user' | 'assistant' | 'system' | 'tool', required
    - `content` union, required
      - string
      - union[]
        - union
          - object — Image content
            - `type` 'image', required
            - `image_url` string, nullable
            - `b64` string, nullable
          - object — Text content
            - `type` 'text', required
            - `text` string, required
          - object — Transaction content
            - `type` 'transaction', required
            - `chain_id` number, required
            - `transaction_hash` string, required
  - `context` object — Context for the AI assistant
    - `from` string — Optional wallet address that will execute transactions
    - `chain_ids` number[] — Optional chain IDs for context
    - `session_id` string, nullable — Optional session ID for conversation continuity. If not provided, a new session will be created
    - `auto_execute_transactions` boolean — Whether to automatically execute transactions. If not provided, the default is false
  - `stream` boolean — Enable server streaming of the AI response

## Response `200`

AI assistant response or SSE stream when stream=true

- object — Chat response
  - `message` string, required — The AI assistant's response
  - `actions` union[], required
    - union
      - object — Sign a transaction
        - `session_id` string, required
        - `request_id` string, required
        - `source` string
        - `type` 'sign_transaction', required
        - `data` object, required
          - `chain_id` number, required
          - `function` string, nullable
          - `to` string, required
          - `value` string, required
          - `data` string, required
      - object — Sign a swap
        - `session_id` string, required
        - `request_id` string, required
        - `source` string
        - `type` 'sign_swap', required
        - `data` object, required
          - `transaction` object, required
            - `chain_id` number, required
            - `function` string, nullable
            - `to` string, required
            - `value` string, required
            - `data` string, required
          - `action` string, nullable, required
          - `intent` object, required
            - `origin_chain_id` number, required
            - `origin_token_address` string, required
            - `destination_chain_id` number, required
            - `destination_token_address` string, required
            - `amount` string, required
            - `sender` string, required
            - `receiver` string, required
            - `maxSteps` number, required
          - `from_token` object, required
            - `address` string, required
            - `chain_id` number, required
            - `amount` string, required
            - `symbol` string, required
            - `decimals` number, required
            - `price` number, nullable, required
          - `to_token` object, required
            - `address` string, required
            - `chain_id` number, required
            - `amount` string, required
            - `symbol` string, required
            - `decimals` number, required
            - `price` number, nullable, required
      - object — Monitor a transaction
        - `session_id` string, required
        - `request_id` string, required
        - `source` string
        - `type` 'monitor_transaction', required
        - `data` object, required
          - `transaction_id` string, required
  - `session_id` string, required
  - `request_id` string, required

---

[API](https://skmtc.net/thirdweb/apis/thirdweb-api.md) · [All operations](https://skmtc.net/thirdweb/apis/thirdweb-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/thirdweb/thirdweb-api/revisions/fb4cb67da1c7/schema)
