DEV Community

Cover image for How to Give Your AI Agent Access to Medium Data
AlterLab
AlterLab

Posted on • Originally published at alterlab.io

How to Give Your AI Agent Access to Medium Data

How to Give Your AI Agent Access to Medium Data

Disclaimer: This guide covers accessing publicly available data. Always review a site's robots.txt and Terms of Service before automated access.

TL;DR

To give an AI agent access to Medium data, use a structured extraction API like AlterLab to bypass bot detection and return JSON instead of raw HTML. This allows the agent to feed a RAG pipeline or knowledge base directly with clean text, removing the need for the LLM to parse complex DOM structures.

Why AI agents need Medium data

For AI engineers building agentic systems, Medium is a primary source of high-signal technical discourse. Raw web access is insufficient; agents need curated, structured data to perform complex reasoning tasks.

Content Intelligence

Agents can monitor specific tags or publications to identify emerging technical trends. By extracting headlines, author bios, and body text, an agent can synthesize "the current state of LLM orchestration" by analyzing the last 50 high-engagement articles on Medium.

Thought Leader Monitoring

By tracking specific authors, an agent can build a knowledge base of a subject matter expert's philosophy. This allows a RAG pipeline to answer questions using the specific voice and logic of a particular industry leader.

Topic Trend Analysis

Agents can perform quantitative analysis on how often certain keywords appear across Medium's tech publications over time. This transforms a qualitative reading experience into a quantitative data stream for market research agents.

Why raw HTTP requests fail for agents

If you attempt to use requests or httpx in a Python agent, you will likely encounter a 403 Forbidden or a CAPTCHA. This happens because Medium employs sophisticated bot detection to prevent scraping.

For an AI agent, these failures are more than just errors; they are "context killers." When a tool call fails, the LLM often hallucinates a reason for the failure or enters a retry loop that wastes your token budget.

Common failure points for agents:

  • JavaScript Rendering: Medium's content is dynamically loaded. A simple GET request returns a skeleton page, leaving the agent with no actual content to analyze.
  • Rate Limiting: Rapid-fire requests from a single IP will trigger a block, killing the agent's pipeline mid-execution.
  • Token Waste: Feeding raw HTML into an LLM context window is inefficient. You waste thousands of tokens on <div> and <span> tags instead of the actual article text.

Connecting your agent to Medium via AlterLab

The most efficient way to connect an agent is via the Extract API docs. Instead of returning HTML, the Extract API uses a schema to return structured JSON. This means your agent receives exactly what it needs—title, author, and content—without the noise.

Using the Extract API

To get started, follow the Getting started guide to configure your API key.

```python title="agent_medium_extract.py" {6-11}

client = alterlab.Client("YOUR_API_KEY")

Extract structured data without manual parsing

result = client.extract(
url="https://medium.com/@username/article-slug",
schema={
"title": "string",
"author": "string",
"content": "string",
"publish_date": "string"
}
)

print(result.data) # Returns a clean dict ready for your LLM context




For those building in other languages, the cURL implementation is straightforward:



```bash title="Terminal"
curl -X POST https://api.alterlab.io/api/v1/extract/templates/{template_id} \
  -H "X-API-Key: YOUR_KEY" \
  -d '{"url": "https://medium.com/@username/article-slug", "schema": {"title": "string", "content": "string"}}'
Enter fullscreen mode Exit fullscreen mode

Using the Search API for Medium queries

When an agent doesn't have a specific URL, it needs a discovery mechanism. The Search API allows your agent to query Medium and receive a list of relevant URLs to then process through the Extract API.

By using /api/v1/search/schedules/{schedule_id}/run, you can automate the discovery of new articles. Your agent can trigger a search for "AI Agents" and receive a structured list of the most recent public posts.

```bash title="Terminal"
curl -X POST https://api.alterlab.io/api/v1/search/schedules/search_id_123/run \
-H "X-API-Key: YOUR_KEY" \
-d '{"query": "site:medium.com AI agents RAG"}'




## MCP integration
For developers using Claude, GPT-4, or Cursor, the Model Context Protocol (MCP) is the gold standard for tool calling. AlterLab provides an MCP server that allows these agents to use web scraping as a native tool.

Instead of writing a custom wrapper, you can simply add the AlterLab MCP server to your configuration. The agent can then decide when it needs to "browse Medium" to find an answer, executing the tool call and receiving structured data directly into its context window. Learn more about [AlterLab for AI Agents](https://alterlab.io/for-ai-agents).

## Building a content intelligence pipeline
A production-ready pipeline moves from discovery to extraction to synthesis. Here is how to structure this workflow for an AI agent.

<div data-infographic="steps">
  <div data-step data-number="1" data-title="Agent requests data" data-description="LLM agent calls AlterLab tool with target URL"></div>
  <div data-step data-number="2" data-title="AlterLab fetches + extracts" data-description="Handles anti-bot, returns structured JSON"></div>
  <div data-step data-number="3" data-title="Agent uses clean data" data-description="No parsing, no retries — data goes straight to LLM context"></div>
</div>

### Implementation Example: The "Trend Analyzer" Agent



```python title="trend_agent.py" {12-22}

from openai import OpenAI

client = alterlab.Client("ALTERLAB_KEY")
llm = OpenAI(api_key="OPENAI_KEY")

def analyze_medium_topic(topic):
    # 1. Search for the topic on Medium
    search_results = client.search(query=f"site:medium.com {topic}")
    top_url = search_results[0]['url']

    # 2. Extract structured content
    article_data = client.extract(
        url=top_url,
        schema={"title": "string", "body": "string"}
    )

    # 3. Synthesize with LLM
    prompt = f"Analyze this article and summarize the core thesis: {article_data['body']}"
    response = llm.chat.completions.create(
        model="gpt-4-turbo",
        messages=[{"role": "user", "content": prompt}]
    )
    return response.choices[0].message.content

print(analyze_medium_topic("Agentic Workflows"))
Enter fullscreen mode Exit fullscreen mode

Key takeaways

  • Avoid Raw HTML: Use structured extraction to save tokens and reduce LLM hallucinations.
  • Bypass Blocks: Use a dedicated API to handle rotating proxies and JavaScript rendering.
  • Integrate via MCP: Use the MCP server for seamless tool calling in modern AI IDEs.
  • Stay Compliant: Always respect robots.txt and focus on public data.

For scaling these pipelines, review the AlterLab pricing to find a plan that fits your agent's request volume.

Top comments (0)