APIs are only supported if substrate cli is running on a local setup and not in docker. check out developer notes on how to run substrate-cli setup in local.
api-server will start on http://localhost:8080.
using client (postman or any other client), POST req, http://localhost:8080/api/spin-request, below is the JSON formatted request body,
{
"prompt":"build me an elegant portfolio website with dark theme for a full stack developer",
"model":"anthropic",
"clustername":"folio-demo"
}
Using CURL request,
curl -X POST http://localhost:8080/api/spin-request \
-H "Content-Type: application/json" \
-d '{
"prompt": "build me an elegant portfolio website with dark theme for a full stack developer",
"model": "anthropic",
"clustername": "folio-demo"
}'
supported LLMs – anthropic, openai, gemini.
Integrating Websockets For Realtime updates.
api-server by default supports websockets to give you realtime updates for the current cluster processing. example code given below to establish a socket connection to api-server.
let socket: any;
export default function getWebSocket() {
if (typeof window === 'undefined') return null; // SSR-safe
if (socket && socket.readyState <= 1) {
// OPEN or CONNECTING
return socket;
}
socket = new WebSocket('ws://localhost:8080/ws');
socket.onopen = () => {
console.log('WebSocket connected');
};
socket.onclose = () => {
console.log('WebSocket closed');
socket = null;
};
socket.onerror = (err: Error) => {
console.error('WebSocket error', err);
socket = null;
};
return socket;
}