# Building a Style-Mimicking News Bot with Grok API

> Recipe for scraping news URLs and rewriting them in your voice using Grok

This tutorial shows how to build an automated news-rewriting bot using Python and xAI's Grok API via its OpenAI-compatible endpoint. It scrapes article text from a provided URL and prompts the model to summarize it using few-shot style examples from your own writing. It serves as a practical, lightweight template for automating newsletter drafting or social media commentary.

## How it works

The xAI API is OpenAI-compatible: use the openai library with base\_url https://api.x.ai/v1 and model grok-beta (XAI\_API\_KEY from environment). Setup: create an account at x.ai, generate an API key, get $25 free credits. Build: 1) fetch\_news\_content(url) — requests.get with a browser User-Agent header, then BeautifulSoup to clean the article text. 2) Define my\_writing\_style by pasting sample posts (e.g. an emoji-headed rundown: 'The Rundown: ... The details: ...'). 3) Set a system\_message and build prompt = f"Write a post about this news: {news\_content}". 4) Call generate\_response(client, system\_message, prompt) and print the completion.choices\[0\].message.content. Result shown: entering a URL produces a formatted post ('Coffee Brand Brews Up AI-Made Video Magic') in the author's rundown style with linked tool suggestions. Notebook runs in Google Colab (xAI.ipynb).

## What it is for

- Turn news articles into drafts for a daily tech or industry newsletter
- Repurpose online articles into structured social media updates in your own voice
- Test and integrate the xAI Grok API into Python automation workflows

## Key points

- Uses the standard OpenAI Python SDK configured with xAI's base URL
- Scrapes and cleans news article content via Requests and BeautifulSoup
- Conditioned on sample posts to match specific formatting and tone
- Generates structured rundown summaries from raw web URLs
- Runs self-contained in a Google Colab notebook

## Pricing

Free tutorial; xAI API requires credits ($25 free credit upon sign-up).

## Details

- Type: Tip
- Category: [AI](https://xiry.app/topics/ai.md)
- Topic: [AI Workflows](https://xiry.app/topics/development/ai-workflows.md)
- Open source: no
- Platforms: API, Web
- For: Developers, newsletter creators, and social media managers experimenting with the xAI API
- Alternative to: OpenAI API workflows, Anthropic Claude API workflows
- Tags: grok, xai, python, scraping, newsletter, prompt engineering

## Why it was saved

- [@dr_cintas, 8 November 2024](https://x.com/dr_cintas/status/1854953643747037203): Shows how to clone your own writing style and turn any article into a newsletter-style post using the Grok API's OpenAI-compatible endpoint.

## Related

- [Animated Skeuomorphic 3D Icon Workflow](https://xiry.app/resources/animated-skeuomorphic-3d-icon-workflow): Workflow for generating and animating Airbnb-style isometric 3D icons using AI (Tip, Free)
- [Audit-Then-Execute Animation Workflow](https://xiry.app/resources/audit-then-execute-animation-workflow): Two-stage AI workflow for auditing and fixing UI animations across codebases (Tip, Free)
- [Xcode + Cursor AI App Prototyping Workflow](https://xiry.app/resources/xcode-cursor-ai-app-prototyping-workflow): A fast iOS development workflow combining Perplexity, Cursor, and Xcode (Tip, Free)
- [YouTube Comments to Insights Workflow](https://xiry.app/resources/youtube-comments-to-insights-workflow): Four-step AI agent pipeline to extract audience insights from YouTube comments (Framework, Free)
- [AutoAgent](https://xiry.app/resources/autoagent): Autonomous harness engineering framework that optimizes AI agent setups overnight (GitHub repo, Open source)
- [browser-use](https://xiry.app/resources/browser-use): Open-source Python library enabling AI agents to control web browsers. (GitHub repo, Open source)

Updated 11 October 2026. Page: https://xiry.app/resources/building-a-style-mimicking-news-bot-with-grok-api

Make your own library: Xiry takes your saved reels, tweets, Reddit bookmarks and Watch Later videos, makes them searchable and pulls the useful stuff out, like this library. It's invite-only for now; join the waitlist at https://xiry.app/#waitlist.
