This short guide shows you how to call ChainGPT’s Web3 LLM in under five minutes—either with plain HTTPS or the official JavaScript SDK. Everything here mirrors the internal Tech‑Team reference, not the older public docs.
If you don’t treat the response as a stream, cURL (or your HTTP client) waits until the LLM finishes, then returns one JSON:
-N turns off buffering so you see partial chunks instantly. Concatenate chunks on arrival until the connection closes.
Subsequent calls with the same sdkUniqueId and chatHistory:"on" include the prior Q&A so the bot answers in context.
Cost impact: chatHistory:"on" consumes +0.5 credits per request.
Set useCustomContext:true; include only the fields you need. Omit contextInjection to fall back to the default context configured in AI Hub.
createChatBlob() buffers the /chat/stream response for you.
SDK parameters match the REST fields 1‑for‑1.
Hide the key. Never embed it in client JavaScript—proxy via your backend.
Watch credits. One call = 0.5 credits; history = +0.5. Set alerts.
Use unique sdkUniqueId. One per user/session keeps histories clean.
You’re now ready to integrate ChainGPT using the exact endpoints and parameters defined by the Tech Team. For deeper dives, see the full or . Happy building!
Stay updated. Check the npm changelog for new SDK features or model IDs.
ChainGPT account + API key
Create a key in AI Hub → API Dashboard and copy it once.
Credits
Each request = 0.5 credits.Turning chatHistory on adds +0.5 credits per call
HTTP client
cURL, Postman, fetch, axios, etc.
(If using SDK) Node ≥ 14
Install from npm.
Secure key storage
Put the key in an env var, secret manager, or server config—never ship it to the browser.
REST API
Any language / server
POST https://api.chaingpt.org/chat/stream (single endpoint for blob and streaming)
JavaScript SDK
Node or a build‑step web app
npm install @chaingpt/generalchat → call createChatBlob() or createChatStream()
401
Missing / bad API key
Check Authorization header.
402 / 403
Out of credits
Top‑up in AI Hub.
400
Bad JSON / missing field
Verify model and question.
5xx
Server error
Retry after brief delay.
Authorization: Bearer $CHAINGPT_API_KEY
Content-Type: application/json
POST https://api.chaingpt.org/chat/streamcurl -X POST https://api.chaingpt.org/chat/stream \
-H "Authorization: Bearer $CHAINGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model":"general_assistant",
"question":"Hello, ChainGPT! Who are you?",
"chatHistory":"off"
}'{ "status":true,
"data": { "bot": "Hello! I’m ChainGPT, a Web3‑savvy AI assistant…" } }curl -N -X POST https://api.chaingpt.org/chat/stream \
-H "Authorization: Bearer $CHAINGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model":"general_assistant",
"question":"Give me the latest ETH stats.",
"chatHistory":"off"
}'curl -X POST https://api.chaingpt.org/chat/stream \
-H "Authorization: Bearer $CHAINGPT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model":"general_assistant",
"question":"Remember my token ABC and what it does.",
"chatHistory":"on",
"sdkUniqueId":"user42"
}'{
"question":"Explain our project.",
"useCustomContext":true,
"contextInjection":{
"companyName":"ABC Crypto",
"companyDescription":"A DeFi yield platform",
"aiTone":"PRE_SET_TONE",
"selectedTone":"FRIENDLY"
}
}npm install @chaingpt/generalchat
# or
yarn add @chaingpt/generalchatimport { GeneralChat } from "@chaingpt/generalchat";
const chat = new GeneralChat({ apiKey: process.env.CHAINGPT_API_KEY });const res = await chat.createChatBlob({
question: "Hi, what is ChainGPT?",
chatHistory: "off"
});
console.log(res.data.bot);const stream = await chat.createChatStream({
question: "Summarise the last BTC block.",
chatHistory: "off"
});
for await (const chunk of stream) process.stdout.write(chunk);await chat.createChatBlob({
question: "Track ABC token price.",
chatHistory: "on",
sdkUniqueId: "user42",
useCustomContext: true
});