Guides / How to build

How to Build an AI Writing Tool: Prompts, Keys, Costs and Limits

How to build an AI writing tool: pick one writing job, design prompt templates, call a model API with your own key, control costs, and avoid common traps.

Mythex Team · 2026-09-29 · 6 min read

To build an AI writing tool, choose one specific writing job, such as product descriptions, cover letters or meeting summaries, and turn it into a form: the inputs the user fills in, a prompt template you've tested, and an output shown in an editor they can change and save. The writing itself comes from a language model you call through an API with your own key, from your server, never the browser. What makes the tool worth using is how well you understand the job, not the model.

Why "one job" matters

General-purpose chat assistants already write anything, so a new tool that "helps you write" competes with them head on. A tool for a narrow job wins because it:

  • Asks for the right inputs. A property listing writer asks for bedrooms, location and standout features, so users don't have to remember them.
  • Hides the prompt. You spend hours getting the instructions right once; users get the benefit in one click.
  • Produces a consistent format. Same structure, length and tone every time, which matters when the output goes straight into a website or a CRM.
  • Fits into a workflow. Saved drafts, templates per client, a copy button that pastes in the right format.

Good first jobs are repetitive, have a clear "good" and "bad" version, and are done by a group you can reach: estate agents, recruiters, shop owners, teachers writing report comments.

What an AI writing tool is made of

PartWhat it does
Input formThe fields for this job: topic, audience, tone, length, key facts, examples
Prompt templateInstructions plus the user's inputs, assembled on the server
Model API callYour server sends the prompt to the provider using your key
Streaming outputText appears as it's generated, so the user isn't staring at a spinner
EditorThe user edits the result; the AI's draft is a starting point
Saved documentsDrafts, history and reusable templates, stored in a database
Accounts and limitsWho the user is, and how much they can generate
Billing (if paid)Plans or credits, usually through a payment provider such as Stripe

Decisions to make before you build

Which model provider

You bring your own API key from a provider such as OpenAI, Anthropic or Google. Pick based on writing quality for your job, speed and price, and test two or three on the same set of real inputs before deciding. Keep the provider behind one function in your code so you can switch later. Our guide on how to use LLM APIs explains tokens, keys and pricing models; for provider-specific setup see integrating the OpenAI API and integrating the Claude API.

How you'll control costs

Every generation costs you money, and a free plan can be abused. Set a monthly spending limit in the provider's dashboard, cap generations per user per day in your app, limit input and output length, and pick a cheaper model for simple jobs. Don't quote users a cost per generation until you've measured real usage from your own provider bills.

Free, paid or credits

A small free allowance helps people try it. After that, a monthly plan with a generous cap is easy to understand; credits suit tools where some generations are much larger than others. See how to price a SaaS product.

What you store

Users may paste in confidential material: client details, unreleased product plans, student information. Decide what you keep, for how long, and whether it's sent to the provider in a way that may be retained. Read your provider's data policy and summarise it plainly in your privacy policy.

Write the prompt template like a brief

The prompt decides most of the output quality. Treat it like a brief for a freelance writer:

  1. Role and job: "You write listings for UK residential property."
  2. Rules: length, structure, what to avoid ("no invented features", "no superlatives like 'stunning'").
  3. The user's inputs, clearly labelled.
  4. An example of a good output, if you have one.
  5. The format: headings, bullet points, plain text or Markdown.

Build a test set of ten to twenty real inputs and check the outputs every time you change the prompt. Small wording changes can fix one case and break three others.

A first prompt for an AI builder

Build a web app called ListingWriter that writes property listing descriptions for estate agents. After login, the user sees their saved listings and a "New listing" form with fields: property type, bedrooms, bathrooms, area, key features (one per line), nearby amenities, tone (professional, warm or concise) and length (short or long). On submit, the server builds a prompt from these fields and calls the AI provider using the secret AI_API_KEY; stream the text into an editor on the page. The user can edit, save, copy and regenerate. Save listings to a database, and each user only sees their own. Limit each user to 30 generations a day, enforced on the server, and show how many are left. Never send the API key to the browser. Clean, simple design.

When the builder needs the key, add it as a secret in the project settings, not pasted into the chat text or the code.

Build it step by step

  1. Get the core loop working: form, server call, streamed output, editor. Test with your real inputs.
  2. Tune the prompt against your test set until most outputs need only light edits.
  3. Add the database for saved drafts, then accounts, then check that one user can't see another's drafts by changing an ID in the URL.
  4. Add limits: daily caps per user, maximum input length, and a clear message when a limit is hit.
  5. Handle failures: the provider will occasionally time out or return an error. Show a friendly message and don't count failed generations against the user.
  6. Add billing if you're charging; build it in test mode first. See how to add payments to your app.
  7. Security pass. Confirm the key isn't in any browser code, and that the generate endpoint rejects logged-out users.
  8. Put it in front of five people who do this job and watch them use it.

Common mistakes

  • Building a general "AI writer". It's hard to explain and hard to beat the chat assistants people already use.
  • Calling the model from the browser. Anyone can copy your key and spend your money.
  • No usage limits. One script can run up a large bill overnight.
  • Presenting output as fact. Models invent details. Tell users to check facts, and write prompts that forbid adding information not in the inputs.
  • Promising to "beat AI detectors" or produce "plagiarism-free" text. You can't guarantee either, and it attracts misuse.
  • Changing the prompt without a test set, then discovering quality dropped for half your users.

When a ready-made product is the better choice

If the writing job is general, such as emails, blog drafts or rewording, the AI assistants and the writing features already built into office and email software are probably enough, and cheaper than building. Established AI copywriting tools also cover common marketing formats with team features. Build your own when the job is specific to an industry or workflow, when you need your own data or house style in every output, or when you want to sell a focused tool to a group you know well.

Building it with Mythex

Mythex is an AI app builder: you describe the tool, and it builds the form, the server-side call, the editor and the saved drafts in a live preview, then publishes it to a public URL. The AI inside your tool uses your own provider key, stored as a project secret (Mythex shows a secrets card in chat when it needs one), and usage is billed to your provider account, not to Mythex build credits. Mythex doesn't include tokens for your app's users or built-in rate limits; you ask for limits and test them.

When you ask to save drafts, Mythex adds a Postgres database to the project. Login for your users uses an auth approach you choose, and paid plans use your own Stripe account. The docs on adding AI with your own API keys and AI inside your app have starter prompts, and how to add AI features to your app covers smaller AI features you can add to an existing product.

Questions

Do I need to train my own model to build an AI writing tool?

No. Almost all AI writing tools call an existing language model through an API and add value with prompts, structure, context and a workflow built around one job. Training a model is rarely worth it for a first version.

How much does it cost to run an AI writing tool?

You pay the model provider per token, roughly per word read and written, so costs grow with usage and output length. Check your provider's current pricing, set a monthly spending limit in their dashboard, and cap usage per user in your app.

How is an AI writing tool different from just using a chatbot?

A good writing tool does one job with the right inputs already asked for, a tested prompt behind the scenes, a consistent output format, and a place to save, edit and reuse drafts. The user fills in a form instead of writing a prompt.

Can I keep my API key safe in a writing app?

Yes, if the model is only ever called from your server. Store the key as a secret on the server, never in browser code, and make the browser call your own endpoint, which checks the user and their limits before calling the provider.

Keep reading

  • How to Add AI Features to Your App — Add summaries, chat, data extraction and classification to your app with an LLM API — keeping keys safe, costs under control and output trustworthy.
  • How to Build a Blog with AI: Posts, Editor, SEO and Hosting — Build your own blog with an AI app builder: posts, an editor, categories, newsletter signup and SEO search engines can read, plus when a platform fits better.
  • How to Build a Booking App: Slots, Availability, Reminders and Deposits — How to build a booking app with AI: services, availability and time slots, double-booking rules, time zones, reminders, deposits, and when Calendly is enough.
  • How to Build a Budget App: Categories, Transactions, Imports and Reports — Build a personal or household budget app: budgeting methods, transactions, CSV imports vs bank connections, handling money correctly, and privacy.
  • How to Build a Changelog Page: Entries, Tags, RSS and 'What's New' — How to build a product changelog page: what each entry needs, files vs database, tags, RSS, email updates, an in-app 'what's new' badge, and writing tips.
  • How to Build a Church Website: Services, Sermons, Events and Giving — How to build a church website that helps visitors find you: service times, sermons, events, online giving, privacy for members and children, and an AI prompt.

Start building free · Templates · Docs