> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kymaapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Content Generation Pipeline

> Batch content generation with structured JSON output.

## Best Model for This

| Model           | Why                             | Cost per article |
| --------------- | ------------------------------- | ---------------- |
| `deepseek-v3`   | GPT-5 class quality, best value | \~\$0.004        |
| `qwen-3.6-plus` | Most creative, best prose       | \~\$0.003        |
| `llama-3.3-70b` | Fastest for high-volume batches | \~\$0.006        |

Costs assume \~500 tokens input + \~800 tokens output per article.

## Quick Start

<CodeGroup>
  ```python Python theme={null}
  import json
  import asyncio
  from openai import AsyncOpenAI

  client = AsyncOpenAI(
      base_url="https://kymaapi.com/v1",
      api_key="ky-your-api-key"
  )

  async def generate_article(topic: str) -> dict:
      # Step 1: Generate structured outline
      outline_resp = await client.chat.completions.create(
          model="deepseek-v3",
          messages=[{
              "role": "user",
              "content": f"Create a blog post outline for: {topic}. "
                         "Return JSON: {{\"title\": str, \"sections\": [str]}}"
          }],
          response_format={"type": "json_object"},
          temperature=0.7
      )
      outline = json.loads(outline_resp.choices[0].message.content)

      # Step 2: Expand each section
      sections = []
      for section in outline["sections"]:
          resp = await client.chat.completions.create(
              model="deepseek-v3",
              messages=[{"role": "user", "content": f"Write 2 paragraphs for: {section}"}],
              temperature=0.8
          )
          sections.append(resp.choices[0].message.content)

      return {"title": outline["title"], "sections": sections}

  # Batch multiple articles in parallel
  topics = ["AI in healthcare", "Future of remote work", "Climate tech startups"]
  articles = asyncio.run(asyncio.gather(*[generate_article(t) for t in topics]))
  for a in articles:
      print(f"# {a['title']}\n")
  ```

  ```javascript JavaScript theme={null}
  import OpenAI from "openai";

  const client = new OpenAI({
    baseURL: "https://kymaapi.com/v1",
    apiKey: "ky-your-api-key",
  });

  async function generateArticle(topic) {
    // Step 1: Generate structured outline
    const outlineResp = await client.chat.completions.create({
      model: "deepseek-v3",
      messages: [{
        role: "user",
        content: `Create a blog post outline for: ${topic}. ` +
                 `Return JSON: {"title": string, "sections": string[]}`,
      }],
      response_format: { type: "json_object" },
      temperature: 0.7,
    });
    const outline = JSON.parse(outlineResp.choices[0].message.content);

    // Step 2: Expand each section in parallel
    const sections = await Promise.all(outline.sections.map((section) =>
      client.chat.completions.create({
        model: "deepseek-v3",
        messages: [{ role: "user", content: `Write 2 paragraphs for: ${section}` }],
        temperature: 0.8,
      }).then((r) => r.choices[0].message.content)
    ));

    return { title: outline.title, sections };
  }

  // Batch multiple articles in parallel
  const topics = ["AI in healthcare", "Future of remote work", "Climate tech startups"];
  const articles = await Promise.all(topics.map(generateArticle));
  articles.forEach((a) => console.log(`# ${a.title}\n`));
  ```
</CodeGroup>

## Tips & Best Practices

* **Use `response_format: json_object`** — guarantees valid JSON output, no need to parse freeform text.
* **Temperature 0.7–0.9 for creative content** — lower temperatures produce repetitive, generic prose.
* **Batch with `asyncio.gather` / `Promise.all`** — parallel generation cuts wall-clock time by 5-10x.
* **Two-pass pipeline beats one big prompt** — outline first, then expand. Better structure, more coherent output.

## Cost Estimate

| Volume           | Model           | Monthly cost  |
| ---------------- | --------------- | ------------- |
| 100 articles/day | `deepseek-v3`   | \~\$12/month  |
| 1K articles/day  | `deepseek-v3`   | \~\$120/month |
| 1K articles/day  | `llama-3.3-70b` | \~\$180/month |

Assumes 500 tokens input + 800 tokens output per article (outline + full content, two API calls).

## Next Steps

* [Structured Outputs](/guides/structured-outputs) — enforce JSON schemas
* [Prompt Caching](/guides/prompt-caching) — cache system prompts for repeated pipelines
* [Model Aliases](/guides/model-aliases) — use `best` for highest quality output
