Automate Web Publishing with AI + the htmlpub API
htmlpub Team•Static site generators are great for traditional workflows, but what if you want to publish websites directly from code, CI/CD pipelines, or AI agents? The htmlpub API lets you programmatically publish HTML pages with a single HTTP request—no git commits, no build steps, no deployment config.
Why Automate Web Publishing
The htmlpub API unlocks powerful automation patterns:
- CI/CD for content: Trigger deployments from GitHub Actions, GitLab CI, or any automation platform
- Batch publishing: Generate and publish dozens of pages from templates or data sources
- AI content pipelines: Chain LLM-generated HTML directly to production URLs
- Dynamic site generation: Build pages on-demand from external APIs or databases
- Scheduled updates: Use cron jobs to refresh content automatically
If you're building with AI code generators like Claude Code, GPT-4, or Cursor, the API becomes even more powerful—your AI assistant can design, build, and deploy websites in a single conversation.
Getting Your API Key
API access requires the Pro plan ($25/month), which includes up to 250 pages. Once you're on Pro:
- Go to /dashboard/api-keys in your htmlpub dashboard
- Click "Create API Key" and give it a descriptive name
- Copy your key—it starts with
hp_live_for production orhp_test_for testing - Store it securely (environment variables, secret manager, or password vault)
Never commit API keys to git repositories or share them publicly. Treat them like passwords.
Your First API Call
Publishing a page is a single PUT request. Here's the simplest example using curl:
curl -X PUT https://htmlpub.com/api/pages/hello-world \
-H "Authorization: Bearer hp_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html": "<h1>Hello World</h1>"}'
The API responds with your live URL:
{
"id": "cm1a2b3c4d5e6f7g8h9i0",
"slug": "hello-world",
"url": "/p/hello-world"
}
Your page is live instantly at https://htmlpub.com/p/hello-world. Update it anytime by sending another PUT request to the same endpoint.
Building an AI Publishing Pipeline
Here's where it gets interesting. Combine OpenAI's API with htmlpub to generate and publish websites programmatically:
import openai, requests
# Generate HTML with AI
response = openai.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Create a single-file HTML landing page for a coffee shop called Bean & Brew. Include menu, hours, location. All CSS inline, responsive design."}]
)
html = response.choices[0].message.content
# Publish to htmlpub
result = requests.put(
"https://htmlpub.com/api/pages/bean-and-brew",
headers={"Authorization": "Bearer hp_live_YOUR_API_KEY", "Content-Type": "application/json"},
json={"html": html}
)
print(f"Live at: {result.json()['url']}")
This script generates a complete landing page with AI and publishes it in seconds. You can extend this to batch-generate pages from CSV files, APIs, or databases.
Claude Code One-Shot Publishing
If you're using Claude Code or similar AI coding assistants, you can publish websites with a single prompt. Just give Claude your API key and describe what you want:
I have an htmlpub.com API key: hp_live_YOUR_KEY
Build me a portfolio website and publish it using the htmlpub API:
1. Create the HTML with inline CSS (responsive, dark mode)
2. PUT it to https://htmlpub.com/api/pages/my-portfolio with Bearer auth
3. Show me the live URL when done
Claude will generate the HTML, make the API call, and return your live URL—all without leaving the conversation. This workflow is perfect for rapid prototyping, client demos, or iterative design with AI feedback loops.
Multi-Page Sites with the Sites API
Publishing individual pages is great for one-offs, but what about multi-page sites with shared navigation? Use the Sites API:
# Create a site
curl -X POST https://htmlpub.com/api/sites \
-H "Authorization: Bearer hp_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "My Portfolio", "slug": "portfolio"}'
Then publish pages that belong to that site:
curl -X PUT https://htmlpub.com/api/pages/about \
-H "Authorization: Bearer hp_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"html": "<h1>About Me</h1>", "siteId": "site_abc123"}'
Pages in a site are accessible under /s/{site-slug}/{page-slug} and can link to each other using those paths.
Uploading Assets
Need images, fonts, or other static files? Use the assets endpoint:
curl -X POST https://htmlpub.com/api/pages/my-page/assets \
-H "Authorization: Bearer hp_live_YOUR_API_KEY" \
-F "[email protected]"
The API returns the asset metadata and URL:
{
"asset": { "id": "asset_abc123", "filename": "logo.png" },
"url": "https://htmlpub.com/api/pages/my-page/assets/asset_abc123"
}
Reference that URL in your HTML. Assets are served with immutable cache headers for performance.
Custom Domains
Ready to go live with your own domain? Connect it via the API:
curl -X POST https://htmlpub.com/api/custom-domains \
-H "Authorization: Bearer hp_live_YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"domain": "www.example.com", "pageId": "YOUR_PAGE_ID"}'
The API returns DNS instructions. Add the CNAME record, then verify:
curl -X POST https://htmlpub.com/api/custom-domains/www.example.com/verify \
-H "Authorization: Bearer hp_live_YOUR_API_KEY"
Once verified, your page serves from www.example.com with automatic SSL.
Full API Reference
This guide covers the core workflows. The htmlpub API also supports listing and deleting assets, managing sites with default pages, and analytics (Pro plan).
Check the full API documentation for detailed endpoint specs, or explore the OpenAPI schema to generate client libraries in your language.
Start automating your web publishing workflow today.