Skip to main content

captionpack — Python client for the Caption-Pack API

Turn a topic, audience, and tone into ready-to-post social captions + hashtags, as JSON. Built for developers and AI agents.

Install

pip install captionpack

(Get your API key at the Caption-Pack site — $10 for 500 calls.)

Quickstart

from captionpack import Client

client = Client(api_key="cp_live_...")
pack = client.caption_pack(topic="morning routines", audience="busy parents")
print(pack.captions[0].body, pack.hashtags)

You can also set the CAPTIONPACK_API_KEY environment variable instead of passing api_key=.

Usage

from captionpack import (
    Client,
    AuthenticationError,
    InsufficientCreditsError,
    RateLimitedError,
)

client = Client()  # reads CAPTIONPACK_API_KEY

# Generate captions (1 credit per call)
pack = client.caption_pack(
    topic="password managers",
    audience="small business owners",
    tone="warm",            # warm | bold | professional | playful
    platform="linkedin",    # instagram | linkedin | x | tiktok
    count=5,                # 1-10
    include_hashtags=True,
)
for caption in pack.captions:
    print(caption.hook, "|", caption.body, "|", caption.cta)
print(pack.hashtags)
print("credits left:", pack.credits_remaining)  # from X-Credits-Remaining

# Check balance
balance = client.balance()
print(balance.credits)

# Handle errors explicitly
try:
    pack = client.caption_pack(topic="x", audience="y")
except InsufficientCreditsError as e:
    print("Out of credits — top up:", e.top_up_url)
except RateLimitedError:
    print("Slow down — 60 requests/minute per key.")
except AuthenticationError:
    print("Bad API key.")

Behavior notes

  • One automatic retry on HTTP 429 (with backoff, honoring Retry-After).
  • X-Credits-Remaining is surfaced on every caption_pack result.
  • Point at a local/dev server with Client(api_key=..., base_url="http://localhost:8000").

Development

pip install -e ".[dev]"   # or: pip install -e . && pip install pytest
# integration tests need the API source; set CAPTIONPACK_TEST_API_DIR
CAPTIONPACK_TEST_API_DIR=/path/to/caption-pack-api pytest

Metadata

Release files for captionpack-api 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for captionpack-api 0.1.0
File Size Uploaded
captionpack_api-0.1.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for captionpack-api 0.1.0
File Interpreter ABI Platform
captionpack_api-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.3 kB

Release files / captionpack_api-0.1.0.tar.gz

Download URL captionpack_api-0.1.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e0c8553da3917fa8adf1ca146aae9947fff2ba685c690cfafbfdac961f84f850
BLAKE2b-256 checksum
How to use checksums
7c8af732e951f868b905ccbc4b5a627788c1188716d0064997477bf44793dc1b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / captionpack_api-0.1.0-py3-none-any.whl

Download URL captionpack_api-0.1.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9e1c2f2d9a1afb09f0fb08ba541a88b46538e6cac395999cbc24efdd32aa4f8
BLAKE2b-256 checksum
How to use checksums
cdd63230809f4023344da86edc13f4cb4e1f603b0c302ce3f8c8e0faefeb2e04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page