A complete plugin example with both server API and optional frontend UI.
This template is based on the official "clothes recommendation" example from the documentation.
# Install dependencies
pnpm install
# Start development server
pnpm devServer runs at http://localhost:3400
- ✅ Backend API with Edge Runtime
- ✅ Optional frontend UI component
- ✅ Plugin gateway for local development
- ✅ Complete manifest with API definitions
- ✅ TypeScript support
default/
├── api/
│ ├── gateway.ts # Plugin gateway (local dev)
│ └── clothes.ts # API endpoint implementation
├── public/
│ ├── manifest-dev.json # Development manifest (with gateway)
│ └── manifest.json # Production manifest
├── src/
│ └── pages/
│ └── index.tsx # Frontend UI component
├── package.json
├── tsconfig.json
├── vercel.json
└── README.md
- User asks: "What should I wear today?"
- AI recognizes intent: Needs clothing recommendation
- AI gathers info: Asks for gender and mood
- Plugin called:
recommendClothes({ gender, mood }) - API responds: Returns clothing suggestions
- UI renders: Shows recommendations in chat
- AI summarizes: Provides final advice
{
"api": [{
"url": "http://localhost:3400/api/clothes",
"name": "recommendClothes",
"description": "Recommend clothes based on user's mood",
"parameters": {
"properties": {
"mood": { "type": "string", "enum": ["happy", "sad", ...] },
"gender": { "type": "string", "enum": ["man", "woman"] }
},
"required": ["mood", "gender"]
}
}],
"ui": {
"url": "http://localhost:3400",
"height": 200
},
"gateway": "http://localhost:3400/api/gateway"
}Create a new file in api/:
import { PluginErrorType, createErrorResponse } from '@sperax/plugin-sdk';
export const config = { runtime: 'edge' };
export default async (req: Request) => {
if (req.method !== 'POST') {
return createErrorResponse(PluginErrorType.MethodNotAllowed);
}
const params = await req.json();
// Your logic here
const result = { /* ... */ };
return new Response(JSON.stringify(result));
};Add your API to public/manifest-dev.json:
{
"api": [
{
"url": "http://localhost:3400/api/your-endpoint",
"name": "yourFunction",
"description": "Description for AI",
"parameters": { /* JSON Schema */ }
}
]
}Edit src/pages/index.tsx to create a custom display:
import { fetchPluginMessage } from '@sperax/plugin-sdk';
export default function Render() {
const [data, setData] = useState();
useEffect(() => {
fetchPluginMessage().then(setData);
}, []);
return <div>{/* Your UI */}</div>;
}# Deploy to Vercel
vercel --prodThen update public/manifest.json with production URLs:
- Remove the
gatewayfield - Update
api[].urlto production URLs - Update
ui.urlto production URL
Choose this template when:
- You want AI to summarize the plugin results
- You need backend processing
- You want optional rich UI display
- You're building something like:
- Weather plugins
- Search plugins
- Data lookup tools
- API integrations