API Endpoint
- URL:
https://banner.droplinked.workers.dev/ - Method:
POST - Content-Type:
application/json
Authentication
An API key is required for access. Contact Droplinked support to obtain your API key. Include it in the request headers as follows:- Header:
api-key - Value:
<YOUR_API_KEY>(provided by Droplinked)
Request Format
The API accepts a JSON payload with the following fields:Request Body
| Field | Type | Required | Description |
|---|---|---|---|
description | String | Yes | A brief or detailed description of the company. |
category | String | Yes | The company’s category (e.g., “technology”). |
Example Request Body
Response Format
- Content-Type:
text/plain - Response: A base64-encoded string representing the generated banner image.
Example Response
Guidelines for Banner Generation
The API operates as follows:- Prompt Generation:
- Calls an internal
text_llmservice with the"banner_prompt"command, passingdescriptionandcategory. - Receives a cleaned, Flux-optimized prompt (e.g., “A sleek digital grid with glowing blockchain nodes, corporate banner style, high quality, detailed, professional, digital art”).
- Calls an internal
- Image Generation:
- Uses the Flux.1 Schnell model (
@cf/black-forest-labs/flux-1-schnell). - Fixed dimensions: 1920x512 pixels (divisible by 8 for model compatibility).
- Applies retries (up to 3) with exponential backoff and prompt simplification if generation fails.
- Uses the Flux.1 Schnell model (
- Output:
- Converts the image to base64 using a robust utility function handling various input types.
- Returns only the base64 string, no additional metadata.
JavaScript Example
Below is an example of how to use the Banner Image Generator API in JavaScript with thefetch API, including rendering the image:
Error Handling
The API provides JSON error responses with a debug header (X-Debug-Version):
- 405 Method Not Allowed: If the method isn’t
POST.- Example:
{ "error": "Method not allowed. Use POST." }
- Example:
- 401 Unauthorized: If the API key is missing or invalid.
- Example:
{ "error": "Authentication failed. Invalid API key." }
- Example:
- 400 Bad Request: If
descriptionorcategoryis missing.- Example:
{ "error": "Missing required fields: 'description' and/or 'category'." }
- Example:
- 500 Internal Server Error: If prompt generation, image creation, or base64 conversion fails.
- Example:
{ "error": "Failed to generate image after multiple attempts.", "details": "..." }
- Example:
- 503 Service Unavailable: If the
text_llmservice fails.- Example:
{ "error": "Failed to call text-llm worker.", "details": "..." }
- Example:
Example Error Output
Best Practices
- Input Quality: Provide a detailed
descriptionand relevantcategoryfor optimal banners. - Image Usage: Decode the base64 string client-side to render or save the image (e.g., as PNG).
- Retry Logic: The API includes built-in retries; ensure your client handles final failures gracefully.
- Testing: Test with various inputs to refine the output for your needs.
Worker Code Insights
- Base64 Conversion: The
uint8ArrayToBase64function handles multiple input types (Uint8Array, ArrayBuffer, arrays) and processes large data in chunks (8192 bytes). - Prompt Formatting: The
formatFluxPromptfunction cleans the prompt and adds Flux-specific quality boosters (e.g., “high quality, professional”). - Retries: Implements exponential backoff (starting at 500ms) with prompt simplification across 3 attempts for reliability.
- Debugging: Includes detailed logging and a version header (
X-Debug-Version) for diagnostics.