# Web3 AI Chatbot & LLM

## Web3 AI Chatbot & LLM

A crypto-native large language model with live on-chain data, Nansen Smart Money insights, token analytics, and support for 33+ blockchains. This is the most versatile and cost-effective product in the ChainGPT suite.

### Key Facts

|              |                                                         |
| ------------ | ------------------------------------------------------- |
| **Endpoint** | `POST /chat/stream`                                     |
| **Model**    | `general_assistant`                                     |
| **Cost**     | 0.5 credits per request (1.0 with chat history enabled) |
| **SDK**      | `@chaingpt/generalchat`                                 |
| **Chains**   | 33+ supported blockchains                               |
| **Response** | Server-Sent Events (streaming) or buffered              |

### What It Does

* Answers general crypto and blockchain questions with current data
* Retrieves live on-chain information (balances, transactions, contract state)
* Provides Nansen Smart Money tracking and wallet analytics
* Delivers token analytics including price, volume, market cap, and holder distribution
* Supports conversational context via chat history

### Parameters

| Parameter          | Type    | Required | Description                                                                                                           |
| ------------------ | ------- | -------- | --------------------------------------------------------------------------------------------------------------------- |
| `model`            | string  | Yes      | Must be `"general_assistant"`                                                                                         |
| `question`         | string  | Yes      | The user's question or prompt                                                                                         |
| `chatHistory`      | string  | No       | `"on"` or `"off"` (string, not boolean). Enables conversational memory. Doubles cost to 1.0 credits. Default: `"off"` |
| `sdkUniqueId`      | string  | No       | Unique session identifier for maintaining chat history across requests                                                |
| `useCustomContext` | boolean | No       | Enable custom context injection                                                                                       |
| `contextInjection` | string  | No       | Custom context to inject into the prompt. Requires `useCustomContext: true`                                           |

### Quick Start -- JavaScript

Install the SDK:

```bash
npm install @chaingpt/generalchat
```

#### Buffered Response

```javascript
import { GeneralChat } from "@chaingpt/generalchat";

const client = new GeneralChat({
  apiKey: process.env.CHAINGPT_API_KEY,
});

const response = await client.createChatMessage({
  model: "general_assistant",
  question: "What is the current price of ETH and its 24h volume?",
  chatHistory: "off",
});

console.log(response.data.bot);
```

#### Streaming Response

```javascript
import { GeneralChat } from "@chaingpt/generalchat";

const client = new GeneralChat({
  apiKey: process.env.CHAINGPT_API_KEY,
});

const stream = await client.createChatMessageStream({
  model: "general_assistant",
  question: "Explain how Uniswap V3 concentrated liquidity works",
  chatHistory: "off",
});

stream.on("data", (chunk) => {
  process.stdout.write(chunk.toString());
});

stream.on("end", () => {
  console.log("\n[Stream complete]");
});
```

#### With Chat History

```javascript
const response = await client.createChatMessage({
  model: "general_assistant",
  question: "Now compare that to SushiSwap's approach",
  chatHistory: "on",
  sdkUniqueId: "session-abc-123",
});
```

### Quick Start -- Python

```bash
pip install chaingpt
```

#### Buffered Response

```python
from chaingpt.client import ChainGPTClient

client = ChainGPTClient(api_key="YOUR_API_KEY")

response = client.chat.create(
    model="general_assistant",
    question="What are the top 5 DeFi protocols by TVL?",
    chat_history="off",
)

print(response["data"]["bot"])
```

#### Streaming Response

```python
from chaingpt.client import ChainGPTClient

client = ChainGPTClient(api_key="YOUR_API_KEY")

for chunk in client.chat.create_stream(
    model="general_assistant",
    question="Summarize today's major crypto market movements",
    chat_history="off",
):
    print(chunk, end="", flush=True)
```

### Tips

* Use `chatHistory: "off"` for one-shot questions to save credits.
* Use `sdkUniqueId` to maintain separate conversation threads for different users or sessions.
* Combine with the Crypto News product by injecting recent headlines via `contextInjection` for AI-analyzed market summaries.
* The LLM already has access to live on-chain data -- you do not need to fetch and inject chain data manually.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chaingpt.org/dev-docs-b2b-saas-api-and-sdk/chaingpt-claude-skill-and-plugin/products/web3-ai-chatbot-and-llm.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
