EN ▾
Get API key

Build an Unfiltered AI Script Generator with an API

An unfiltered ai script generator is a small program that keeps your story notes in the prompt, asks the model for one scene at a time and streams the result. This guide builds one against an OpenAI-compatible API, with working Python and Node code.

Updated

Key points

  1. Keep a story bible and recent scenes in the prompt; the window holds 100,000 tokens.
  2. Stream output with stream: true so scenes appear as they are written.
  3. Use JSON mode to get a machine-readable outline before writing scenes.
  4. A 46,000-token prompt plus a 1,500-token scene costs about $0.00765.
Terminal feeding streams of light into stacked script pages, representing an AI script generator workflow

What the generator does

Script here means screenplay, stage play, video narration or interactive dialogue: any text with scenes, speakers and stage directions. The workflow has three parts. A story bible holds the characters, setting, tone and rules. An outline lists the scenes. A loop then writes each scene with the bible and the previous scenes in view, so names and details stay consistent.

The model behind https://api.unfilteredaigenerator.com/v1 is tuned to answer without content refusals for lawful adult use, which matters for scripts with violence, crime, grief or morally grey characters. A model that stops in the middle of a scene to lecture the writer is no use as a drafting tool. Content involving minors in a sexual context is a hard no, and that is the one limit no prompt will change.

Everything below uses the standard chat completions interface, so the official OpenAI SDK works unchanged except for the base URL and key. If you have not got a key yet, the API key page lets new users claim a $0.50 trial in one click.

Step 1: connect and stream a first scene

Start with the smallest working version: a system prompt that sets the role, a user prompt that asks for a scene, and streaming so you see text as it arrives.

from openai import OpenAI

client = OpenAI(
    base_url="https://api.unfilteredaigenerator.com/v1",
    api_key="YOUR_API_KEY",
)

SYSTEM = (
    "You are a screenwriter. Write in standard screenplay format: "
    "scene headings in capitals, action lines in present tense, "
    "character names in capitals above dialogue. "
    "Never break the fourth wall or add commentary."
)

stream = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": SYSTEM},
        {"role": "user", "content": "Scene 1: a night shift at a failing diner. "
                                    "Two strangers, one lie, one unpaid debt."},
    ],
    temperature=0.9,
    stream=True,
)

for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Streaming matters for a script tool because scenes are long. Waiting for a full 1,500-token reply feels slow, while watching it appear feels fast and lets the user stop a bad take early. Keep in mind that a streamed request holds its concurrency slot until the stream ends. A full key allows 8 at once, a trial key 2.

Step 2: build a story bible

The bible is a block of plain text that you place at the top of every request. Keep it short and factual. Long, flowery notes cost tokens and teach the model to write that way.

BIBLE = '''
TITLE: Last Orders
GENRE: crime drama, slow burn, adult audience
TONE: dry, tense, little music, long silences
SETTING: a coastal town in winter, one diner open all night
CHARACTERS:
- MARA (40s): owner of the diner, hides a gambling debt, speaks in short sentences
- DELL (30s): drifter, a former courier, lies easily, hates being touched
- ROOK (50s): collector for a loan shark, polite, never raises his voice
RULES:
- No narration. No jokes at the expense of the plot.
- Keep each scene under 600 words.
'''

Then add the last few scenes as context. A simple approach is to keep a list of finished scenes and send the bible plus the most recent ones. When the history gets long, replace the oldest scenes with a two-sentence summary each.

def build_messages(bible, scenes, instruction, keep=6):
    recent = scenes[-keep:]
    older = scenes[:-keep]
    summary = "\n".join(f"- {s['summary']}" for s in older)
    history = "\n\n".join(s["text"] for s in recent)
    context = f"{bible}\n\nEARLIER SCENES (summaries):\n{summary}\n\nRECENT SCENES:\n{history}"
    return [
        {"role": "system", "content": SYSTEM},
        {"role": "user", "content": context + "\n\nNEXT SCENE: " + instruction},
    ]

With a context window of 100,000 tokens, shared between prompt and reply, you will rarely need to summarize in a short project. A 90-minute screenplay can run to tens of thousands of tokens, so summaries start to pay off late in a long draft.

Step 3: get an outline with JSON mode

Before writing scenes, ask for a structured outline. JSON mode makes the reply parseable without regular expressions. Set response_format and say the word JSON in the prompt.

import json

outline_resp = client.chat.completions.create(
    model="uncensored",
    messages=[
        {"role": "system", "content": "You output only valid JSON."},
        {"role": "user", "content": BIBLE + "\nReturn a JSON object with a key "
            "'scenes': a list of 8 objects, each with 'number', 'location', "
            "'goal' and 'conflict'."},
    ],
    response_format={"type": "json_object"},
    temperature=0.7,
)

outline = json.loads(outline_resp.choices[0].message.content)
for s in outline["scenes"]:
    print(s["number"], s["location"], "-", s["goal"])

Lower the temperature for outlines and raise it for dialogue. If you want repeatable output while you tune a prompt, pass a seed; it is passed through to the model along with top_p, stop and the penalties. Wrap json.loads in a try block and retry once on failure, since a truncated reply is still possible if you set a small max_tokens.

Step 4: write every scene in a loop

Now tie the pieces together. Each iteration builds the messages, streams the scene to the screen and stores the text for the next round.

scenes = []

for item in outline["scenes"]:
    instruction = (f"Scene {item['number']} at {item['location']}. "
                   f"Goal: {item['goal']}. Conflict: {item['conflict']}.")
    messages = build_messages(BIBLE, scenes, instruction)

    text = ""
    stream = client.chat.completions.create(
        model="uncensored", messages=messages, temperature=0.9, stream=True,
    )
    for chunk in stream:
        if chunk.choices and chunk.choices[0].delta.content:
            piece = chunk.choices[0].delta.content
            text += piece
            print(piece, end="", flush=True)
    print("\n" + "-" * 40)

    scenes.append({"text": text, "summary": item["goal"]})

If you build a web front end instead, the same call works in Node with the official SDK. Pass the stream through to the browser with server-sent events.

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.unfilteredaigenerator.com/v1",
  apiKey: process.env.API_KEY,
});

const stream = await client.chat.completions.create({
  model: "uncensored",
  messages: [{ role: "user", content: "Write the opening scene of a noir stage play." }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Keep the key on your server. Never ship it to a browser bundle.

What a script costs to generate

Pricing is $0.15 per 1M input tokens and $0.50 per 1M output tokens. In the loop above, the input is large because the bible and recent scenes are resent on each call, while the output is only the new scene.

Take a mid-draft scene with 46,000 tokens in the prompt and 1,500 tokens written:

  • Input: 46,000 x $0.15 / 1,000,000 = $0.0069
  • Output: 1,500 x $0.50 / 1,000,000 = $0.00075
  • Total: $0.00765

An eight-scene outline with a smaller average prompt of 12,000 tokens and 1,000 output tokens per scene costs $0.0018 + $0.0005 = $0.0023 per scene, or $0.0184 for all eight. Even a 100-scene series at the heavier $0.00765 rate comes to $0.765.

The cost driver is the resent context. If a bill looks high, trim the history, not the bible. The pricing page lists top-ups from $20, with bonuses from $50, and failed requests are not charged.

Pitfalls and how to handle them

  • HTTP 429 with concurrency. You started too many streams at once. A full key allows 8 concurrent requests, so queue scene generation instead of firing all scenes in parallel. Scenes depend on each other anyway.
  • HTTP 429 with rate_limited. Too many requests per minute: 300 on a full key, 60 on a trial key.
  • 429 with a Retry-After header. Temporary overload. Wait the 5 seconds it asks for, then retry.
  • Drift in character voice. Put speech habits into the bible, such as "Mara speaks in short sentences", and keep recent scenes in context.
  • Repetition. Raise frequency_penalty slightly, or lower the scene length in the rules.

A small retry helper is enough for most scripts:

import time
from openai import RateLimitError

def create_with_retry(**kwargs):
    for attempt in range(4):
        try:
            return client.chat.completions.create(**kwargs)
        except RateLimitError:
            time.sleep(5 * (attempt + 1))
    raise RuntimeError("still rate limited after 4 tries")

For connection settings and the full parameter list, see the quickstart.

Prompting tips for better dialogue

The code is the easy part. Most of the quality comes from what you put in the prompt, and a few habits make a visible difference.

Give each character a speech rule

"Rook is polite and never raises his voice" does more than a paragraph of backstory. A rule the model can apply in every line keeps voices apart. Two or three rules per main character are enough.

Say what the scene must change

Weak instructions describe a situation. Strong ones name a change: by the end of the scene Mara must have agreed to something she did not want to agree to. Scenes with a required change have a shape, and the model stops padding.

Constrain the format, not the content

Format rules such as "action lines in present tense, no camera directions" are cheap and reliable. Content rules written as long lists of banned subjects tend to make the output timid. Because this model is tuned not to refuse lawful adult material, you can keep content notes short and spend your tokens on craft.

Use stop sequences for clean cuts

If you generate one scene per call, add a marker such as END SCENE to the instructions and pass it as stop. The model ends where you want, and you do not pay for an extra paragraph you will delete.

Vary temperature by task

Outlines and summaries do well at 0.5 to 0.7. Dialogue and action benefit from 0.9 or a little higher. If a scene comes back flat, raise the temperature a step before you rewrite the prompt.

Adapting the workflow to other script formats

Nothing in the pipeline is tied to screenplays. Change the system prompt and the bible, and the same loop writes other things.

  • Video narration. Ask for short paragraphs with a spoken rhythm, and put the target duration in the bible. A rough rule is about 150 spoken words per minute, so a two-minute segment needs around 300 words.
  • Interactive fiction. Ask for a scene plus three choices in JSON, and feed the player's pick back as the next instruction.
  • Game dialogue. Use tool calling to let the model call a function such as set_flag or give_item while it writes, and apply the result in your game state.
  • Roleplay and companion apps. Keep a short character card in the system prompt and the chat history in the messages list, for adult users who have opted into fiction of that kind.

Tool calling follows the usual chat completions format: define tools, optionally set tool_choice, read the tool_calls in the reply, run them, and send the results back as messages with role: "tool". The docs cover the exact shapes.

Whichever format you pick, remember the process is a loop of small, checkable steps. Generate the outline, read it, fix it, and only then spend tokens on full scenes. That order saves money and avoids rewriting a draft that was built on a weak outline.

Questions and answers

Can I use this for video scripts and narration?

Yes, as long as you want the text. The API writes text only, so any images, voice or video have to come from other tools.

How long can a script be?

The context window is 100,000 tokens, shared between your prompt and the reply. For longer projects, summarize older scenes and keep only the recent ones in full.

Does the model refuse dark themes in fiction?

It is tuned to answer without content refusals for lawful adult use. The one fixed limit is that sexual content involving minors is never allowed.

Which model ID do I use?

Set model to uncensored and use the base URL for this site. Any OpenAI-compatible SDK or client works after that.

Your key is one form away

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

Get API keyRead the docs