EN ▾
Get API key

Seedream API: A Developer's Guide to Text Integration

The Seedream API generates high-quality images and video from text prompts, but its visual output quality depends entirely on the precision of the input text. This guide explains how to use an uncensored text completion API to engineer the exact prompts Seedream needs, ensuring your creative pipelines produce consistent results without content refusals.

Seedream API: A Developer's Guide to Text Integration

Updated

Key points

What is the Seedream API?

The Seedream API is a specialized endpoint designed for generating high-quality visual assets, such as images or video, from text descriptions. While Seedream handles the rendering logic and pixel generation, it relies on the quality of the input text to determine the final output. The API accepts standard text prompts and returns visual data, often in the form of image URLs or base64-encoded streams.

Unlike general-purpose LLMs that chat with you, Seedream is a tool-oriented endpoint. Its primary function is translation from linguistic intent to visual form. Developers integrating Seedream often find that the bottleneck is not the rendering speed, but the precision of the prompt. If the input text is vague or constrained by content filters, the resulting visuals may lack detail or miss specific aesthetic cues.

This is where a dedicated text completion API becomes valuable. By offloading prompt engineering to a text-only model, you can refine your input before it ever reaches the visual generator. This separation of concerns allows you to optimize for text structure, keyword density, and stylistic nuance without waiting for the slower image generation process.

Why Text Completion Powers Seedream

High-fidelity visual outputs from Seedream are directly correlated with the specificity of the prompt. A text completion API allows you to expand simple ideas into detailed, structured descriptions that Seedream can interpret more accurately. For example, instead of sending "a cat on a roof," you can use a text model to generate "a fluffy orange tabby sitting on a red tiled roof at sunset, cinematic lighting, 4k resolution, detailed fur texture."

One significant advantage of using an uncensored text layer is reliability. General-purpose AI models often refuse to generate prompts for certain adult or niche topics, which can break your pipeline if you are building a platform for diverse creative content. An uncensored text API ensures that your prompt generator can describe any lawful concept without arbitrary refusals, giving Seedream the full range of descriptors it needs.

Additionally, text APIs support function calling and JSON modes. This means you can structure your prompts as objects with specific keys (e.g., style, lighting, camera_angle), which Seedream might parse more effectively than free-form text. This structured approach reduces hallucination and improves consistency across multiple generations.

Setting Up the API Client

To integrate a text completion API into your Seedream pipeline, you need a client that supports OpenAI-compatible endpoints. Most modern text APIs adhere to the POST /v1/chat/completions standard. This allows you to use existing SDKs for Python, Node.js, or Go without writing custom HTTP parsers.

Start by obtaining an API key from your text provider. The base URL will typically follow the pattern https://api.cosyvoice.top/v1. You will then configure your client to point to this base URL while sending the model ID uncensored. This ensures that the text model is optimized for creative freedom.

Here is how you might initialize the client in a standard environment:

from openai import OpenAI

client = OpenAI(base_url="https://api.cosyvoice.top/v1", api_key="YOUR_KEY")

resp = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Summarise this thread without softening it."}],
)
print(resp.choices[0].message.content)

Remember to handle authentication headers correctly. The API key should be passed in the Authorization header as a Bearer token. Since Seedream is a separate service, your text API key and Seedream API key are distinct. Ensure you do not mix them in the same request.

Generating Prompts with Context

Context window management is critical when generating long, detailed prompts for Seedream. The text API supports a 100,000-token context window, which is more than enough to hold entire style guides, character sheets, or narrative arcs. You can pass these as system messages or in the conversation history to ensure the generated prompt adheres to your creative constraints.

For example, if you are generating prompts for a series of images, you can maintain a conversation history where the text model remembers the character's appearance from previous turns. This ensures consistency across multiple Seedream generations without you having to manually repeat details in every prompt.

You can also use the stop parameter to control the length of the generated prompt. If Seedream has a maximum token limit for input text, you can set the max_tokens in the text API to match that limit exactly. This prevents truncation issues and ensures that your prompts fit within Seedream's constraints.

Handling JSON Responses

Structured data is often easier for visual APIs to parse than natural language. By using the response_format: {"type": "json_object"} parameter, the text API will return the prompt as a JSON object. This allows you to inject variables directly into your Seedream request payload.

For instance, you can ask the text model to output a JSON object with keys like subject, environment, and style. Your code can then map these keys to Seedream's specific parameters. This approach reduces the need for complex string manipulation or regular expressions to extract key details from the generated text.

JSON mode also helps with error handling. If the text model fails to generate a valid structure, you can catch the JSON parsing error and retry the request. This makes your pipeline more solid compared to relying on free-form text generation, which might occasionally include conversational filler that Seedream interprets as part of the image description.

Streaming for Real-Time Feedback

Streaming responses via Server-Sent Events (SSE) allow you to receive the generated prompt token by token. This is particularly useful for user interfaces where you want to display the prompt as it is being written. It gives users immediate feedback on the direction the text model is taking, allowing them to interrupt or adjust the generation if it starts to drift.

In a Seedream pipeline, streaming can also be used to optimize token usage. If the generated prompt reaches a sufficient level of detail early on, you can stop the streaming request and send the partial text to Seedream. This reduces latency and saves credits, as you are not waiting for the model to generate unnecessary trailing words.

Here is how you might handle a streaming response in a client:

stream = client.chat.completions.create(
    model="uncensored",
    messages=[{"role": "user", "content": "Tell the story in second person."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

The last chunk of a streaming response typically includes the total token usage. This allows you to track costs accurately in real-time, ensuring that your text API usage remains within budget while you iterate on your Seedream prompts.

Token Optimization Strategies

Token efficiency is key to keeping costs low, especially when generating thousands of prompts for Seedream. One strategy is to use system prompts to define the style and constraints, rather than repeating them in every user message. The text API charges for both input and output tokens, so minimizing redundant text is important.

Another strategy is to use few-shot learning. By including a few examples of desired prompt structures in the system prompt, you can guide the model to generate concise, high-quality outputs without needing extensive instructions in every request. This reduces the input token count significantly.

Finally, consider caching common prompt segments. If certain styles or subjects are generated frequently, store them in your database and reuse them. This avoids unnecessary API calls and reduces the load on the text model. However, ensure that the cached prompts are still valid for the current Seedream version, as visual APIs sometimes update their parameter requirements.

Common Integration Pitfalls

One common mistake is assuming that the text API and Seedream share the same token limits. The text API has a 100,000-token context window, but Seedream might have a much lower input limit for prompts. Always check Seedream's documentation for its maximum token allowance and configure the text API's max_tokens accordingly.

Another pitfall is ignoring content filters in the text layer. Even though the text API is uncensored, it still blocks specific content (e.g., sexual content involving minors). If your Seedream pipeline relies on generating diverse adult content, ensure that the text API's limits align with your needs. The uncensored model handles most lawful adult topics, but hard limits still apply.

Rate limiting is another consideration. The text API allows 300 requests per minute per key. If you are generating prompts in bulk for Seedream, you may need to implement a queueing system to avoid hitting this limit. Exceeding the rate limit will result in 429 errors, which can stall your pipeline.

Questions and answers

Does the text API generate images or video for Seedream?

No, the text API is strictly for text completion. It generates the prompt text that you then send to Seedream. Seedream handles the actual image or video rendering. This separation allows you to refine the prompt independently of the visual generation process.

Is the text API compatible with standard OpenAI SDKs?

Yes, the text API follows the OpenAI chat-completions standard. You can use the official OpenAI SDKs for Python, Node.js, and other languages by simply changing the base URL and API key. This makes integration straightforward and reduces the need for custom code.

What happens if the text API refuses a prompt?

The text API is uncensored for most topics, but it does enforce a hard limit on sexual content involving minors. For all other lawful adult, creative, or controversial topics, the model will generate the text without refusal. This ensures that your Seedream pipeline is not blocked by arbitrary content filters.

How much does it cost to generate prompts for Seedream?

The text API charges $0.15 per 1 million input tokens and $0.50 per 1 million output tokens. Since prompts are typically short, the cost per prompt is very low. You can top up your credit by crypto (USDT on TRC20, USDC on Base) with no monthly fees, and unused credit never expires.

Your key is one form away

Create an account, copy the key, change the base URL. That is the whole setup.

Get API key