Metadata-Version: 2.5
Name: langchain-clipcloud
Version: 0.1.0
Summary: LangChain tools for ClipCloud: text to image in 35 styles, with a free daily quota.
Project-URL: Homepage, https://clipcloud.cliplabs.top
Project-URL: Documentation, https://github.com/alexmrgit/langchain-clipcloud#readme
Project-URL: Source, https://github.com/alexmrgit/langchain-clipcloud
Project-URL: API docs, https://clipcloud.cliplabs.top/docs/
Author: ClipLabs
License-Expression: MIT
License-File: LICENSE
Keywords: ai-agents,clipcloud,image-generation,langchain,text-to-image,tools
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Multimedia :: Graphics
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx<1,>=0.27
Requires-Dist: langchain-core<2.0.0,>=0.3.0
Requires-Dist: pydantic<3,>=2.7
Description-Content-Type: text/markdown

# langchain-clipcloud

[![PyPI](https://img.shields.io/pypi/v/langchain-clipcloud?label=PyPI)](https://pypi.org/project/langchain-clipcloud/)
[![Python](https://img.shields.io/pypi/pyversions/langchain-clipcloud)](https://pypi.org/project/langchain-clipcloud/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexmrgit/langchain-clipcloud/blob/main/LICENSE)

LangChain tools for [ClipCloud](https://clipcloud.cliplabs.top): text to image in 35 styles (photo, anime, watercolor, pixel art, Full HD, 4K). ClipCloud is ClipLabs' own image service and runs on ClipLabs servers. Every API key gets 25 free images a day.

```bash
pip install -U langchain-clipcloud
```

## Setup

Get a free key in the [ClipCloud web panel](https://clipcloud.cliplabs.top/panel/) or in the Telegram bot @clipcloudbot. It starts with `clip-`.

```bash
export CLIPCLOUD_API_KEY="clip-..."
```

You can also pay through [api.market](https://api.market/store/cliplabs/clipcloud) or [Apify](https://apify.com/cliplabs/clipcloud-image-generator). The images and the code are the same; only the key changes:

| `route` | Key variable | You pay |
|---|---|---|
| `"direct"` (default) | `CLIPCLOUD_API_KEY` | ClipCloud, the lowest price |
| `"api_market"` | `API_MARKET_KEY` | api.market |
| `"apify"` | `APIFY_TOKEN` | Apify |

Pass `route=` to a tool, or set `CLIPCLOUD_ROUTE`.

## Tools

| Tool | Name for the model | What it does |
|---|---|---|
| `ClipCloudImageGenerator` | `clipcloud_generate_image` | Starts a generation and waits up to `wait_seconds` (120 by default) |
| `ClipCloudGetImage` | `clipcloud_get_image` | Checks a generation by `creation_id` and waits again. Free, safe to repeat |
| `ClipCloudBalance` | `clipcloud_get_balance` | Credits, dollars, free images left today (ClipCloud key only) |

`ClipCloudToolkit` gives all of them with one set of settings. Every tool works with `invoke` and `ainvoke`; the async path uses `httpx.AsyncClient` and never blocks the event loop.

## Use it

```python
from langchain_clipcloud import ClipCloudImageGenerator

tool = ClipCloudImageGenerator(save_dir="images")
print(tool.invoke({"prompt": "A red fox in a snowy forest at dawn, soft light", "style": "HD-HQ"}))
```

```text
Done: 1 image(s), creation_id 9984827b-79b0-4dbc-fb2b-08df4fb8bd41.
Image 1: images/clipcloud-9984827b-1.webp
Cost: 1.9 credits ($0.0048).
```

<img src="https://raw.githubusercontent.com/alexmrgit/langchain-clipcloud/main/assets/example-fox.webp" width="360" alt="The image from this example: a red fox in a snowy forest">

*The image this exact call made.*

Called with a tool call (as an agent does), the tool returns a `ToolMessage`: `content` is that text, `artifact` is a dict with `creation_id`, `status`, `image_urls`, `files`, `censored`, `cost_usd`, `cost_credits`, `free_images_used` and `message`.

Without `save_dir` the tool returns only the ClipCloud links. They are temporary (they work for at least an hour), so set `save_dir` or download the images soon.

In an agent:

```python
from langchain.agents import create_agent
from langchain_clipcloud import ClipCloudToolkit

agent = create_agent(model="claude-sonnet-4-6", tools=ClipCloudToolkit(save_dir="images").get_tools())
agent.invoke({"messages": [{"role": "user", "content": "Make a watercolor of a lighthouse at sunset"}]})
```

## Styles

The style sets the look, the size and the price. `HD-HQ` (1024x1024) is a good default, `lowquality` is the cheapest draft. The tool's description lists all 35 for the model.

![Examples of 12 ClipCloud styles with their sizes](https://raw.githubusercontent.com/alexmrgit/langchain-clipcloud/main/assets/styles.webp)

## Slow styles

Small styles take 1 to 5 minutes. Full HD, 4K and upscaled styles can take 15 minutes or more at busy times. If the images are not ready within `wait_seconds`, the generator returns `status: running` with the `creation_id`, and the text tells the model to call `clipcloud_get_image`. Calling the generator again would start and charge a second generation, so the tool says so too.

```python
from langchain_clipcloud import ClipCloudGetImage

ClipCloudGetImage(save_dir="images").invoke({"creation_id": "0b6c2f9e-...", "wait_seconds": 600})
```

## Rules the tools keep

- The request that starts a generation is sent once. If it breaks off, the tool says the generation may have started and does not repeat it.
- Checks are free and survive temporary errors (network, 429, 502-504) until the wait ends.
- ClipCloud image links are temporary. Set `save_dir` to keep the images; the files are WebP.
- Errors (no balance, wrong key, all images blocked by the content filter) come back to the model as a clear tool error, not an exception.
- Prices: images blocked by the content filter are not charged. See [pricing](https://clipcloud.cliplabs.top/pricing/) (1 credit = $0.0025).

## Settings

| Setting | Default | |
|---|---|---|
| `api_key` | from the route's variable | `SecretStr`, never shown in `repr` |
| `route` | `CLIPCLOUD_ROUTE` or `"direct"` | `"direct"`, `"api_market"`, `"apify"` |
| `wait_seconds` | 120 | how long one call waits |
| `save_dir` | none | folder for the image files |
| `base_url` | ClipCloud | the direct route can use the mirror `https://clipcloud-rumirror.clipai.pro` |
| `soft_id` | none | see below |

**soft_id.** Optional ClipCloud referral ID, direct route only. The package sends none unless you pass `soft_id=`. Leave it empty if you do not have one.

## Plain clients

`ClipCloudClient` and `AsyncClipCloudClient` are also exported, for code that is not an agent:

```python
from langchain_clipcloud import ClipCloudClient

with ClipCloudClient() as cc:
    creation_id = cc.start("A cozy cabin in a snowy forest at dusk", "HD-HQ")
    gen = cc.wait(creation_id, 600, first_delay=15)
    data, ext = cc.download(gen.image_urls[0])
```

## Development

```bash
pip install -e . pytest pytest-asyncio pytest-socket "langchain-tests>=1.2,<2" ruff mypy
make test lint
```

```bash
CLIPCLOUD_API_KEY=clip-... make integration_test
```

Unit tests mock HTTP with `httpx.MockTransport` and include LangChain's standard `ToolsUnitTests`. Integration tests run LangChain's `ToolsIntegrationTests` and live calls on each route whose key is set; they make a few `lowquality` images (about $0.0005 each with a ClipCloud key, $0.001 on api.market, $0.002 on Apify).

## Links

- ClipCloud API docs: https://clipcloud.cliplabs.top/docs/
- Styles and prices: https://clipcloud.cliplabs.top/pricing/
- Other ClipCloud integrations: an MCP server (`clipcloud-mcp`), an n8n node, a WordPress plugin.

MIT license.
