ai-extract-keywords Edge Function — Ai
AIExtracts the top N keywords from text using TF-IDF inspired scoring with built-in English stopword filtering, no external API calls required.
Edge function ai-extract-keywords Extracts the top N keywords from text using TF-IDF inspired scoring with built-in English stopword filtering, no external API calls required.. Deployed on Cloudflare Workers — zero cold starts, globally distributed. Mount it via your Aerostack workspace to call it from any AI agent.
npx aerostack add navin/ai-extract-keywords Use with AI Assistants
MCPConnect Claude, Cursor, or any MCP-compatible client — then call this function by slug
① Add MCP Server
Add this once — access all Aerostack functions from your AI tool.
{
"mcpServers": {
"aerostack": {
"url": "https://mcp.aerostack.dev",
"type": "http"
}
}
} ② Call this function
Ask your AI to use the call_function tool with this slug:
call_function({
slug: "ai-extract-keywords",
args: {
"text": "example_text",
"topN": 10,
"minLength": 3,
"includeScores": false,
"stopwords": null
}
}) ai-extract-keywords — Extract top keywords from text using TF-IDF scoring
Extracts the most relevant keywords from any text using TF-IDF inspired scoring with built-in English stopwords — no external API calls.
API
POST /api/ai-extract-keywords
Request body
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
text |
string | ✅ | — | Text to extract keywords from |
topN |
number | ❌ | 10 |
Maximum keywords to return |
minLength |
number | ❌ | 3 |
Minimum word length to consider |
includeScores |
boolean | ❌ | false |
Return {keyword, score} objects instead of plain strings |
stopwords |
string[] | ❌ | English defaults | Custom stopword list to override built-in list |
Success response (200)
{
"success": true,
"data": {
"keywords": ["machine", "learning", "neural", "network", "training"],
"count": 5
}
}
With includeScores: true:
{
"success": true,
"data": {
"keywords": [
{ "keyword": "machine", "score": 0.0423 },
{ "keyword": "learning", "score": 0.0381 }
],
"count": 2
}
}
Error responses
| Code | HTTP | When |
|---|---|---|
INVALID_INPUT |
400 | Missing or empty text |
INTERNAL_ERROR |
500 | Unexpected error |
Usage
cURL
curl -X POST "$FUNCTION_URL" \
-H "Content-Type: application/json" \
-d '{"text": "Machine learning and AI are transforming the software industry.", "topN": 5, "includeScores": true}'
TypeScript / JavaScript (HTTP)
const response = await fetch(FUNCTION_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: articleBody, topN: 10 }),
});
const { data } = await response.json();
console.log(data.keywords); // ["machine", "learning", ...]
Direct import (Node / Bun / Deno)
import { aiExtractKeywords } from '@aerostack/functions/ai-extract-keywords';
const { keywords } = aiExtractKeywords({ text: document, topN: 15, includeScores: true });
Use Cases
- Auto-tagging blog posts or knowledge base articles for search indexing.
- Extracting topics from user messages to route them to the correct support category.
- Building a keyword-based content recommendation engine without a full NLP pipeline.
Notes
- Scoring is TF-IDF inspired: words that appear frequently but less uniformly score higher.
- Pure numbers are excluded from keyword candidates.
- The built-in stopword list covers ~120 common English function words.
- Pass
stopwords: []to disable all stopword filtering.
Metadata
Tags
Publisher
@navin verified
Build and publish your own functions
Write a TypeScript function, deploy it to the edge, and share it with thousands of developers — in minutes.
More AI Functions
Browse AI Functions →ai-chunk-overlap
by @navin
Splits text into overlapping chunks with configurable size, overlap, and boundary snapping (char, word, sentence) for RAG and embedding pipelines.
ai-context-window-fit
by @navin
Trims a conversation message array to fit within a model's context window using configurable strategies, without making any API calls.
ai-cost-estimate
by @navin
Calculates the API cost for an LLM request given a model name, prompt token count, and completion token count, supporting multiple currencies.
ai-guardrail-injection-detect
by @navin
Scores text for common prompt injection attack patterns including role overrides, instruction leaking, and jailbreak attempts.
ai-language-detect
by @navin
Detects the natural language of a text string using character trigram frequency analysis, supporting 13 languages with no external API calls.
ai-messages-to-prompt
by @navin
Serialises a structured message array into a formatted prompt string for open-source LLMs, supporting ChatML, Llama 2, Alpaca, and plain text formats.
Frequently asked questions
What does the ai-extract-keywords function do? +
ai-extract-keywords is a serverless edge function for ai automation written in aerostack. Deploy it to Cloudflare Workers via your Aerostack workspace.
How do I deploy the ai-extract-keywords function? +
Install the Aerostack CLI and run: ```bash aerostack deploy function @navin/ai-extract-keywords ``` It will be live on Cloudflare Workers in seconds.
What runtime does ai-extract-keywords use? +
ai-extract-keywords runs on aerostack on the Cloudflare Workers edge runtime — zero cold starts, globally distributed.
Can I customise the ai-extract-keywords function? +
Yes. Fork the function from your Aerostack dashboard, modify the source, and redeploy. All changes are version-controlled.