Skip to main content

Get Your API Key

  1. Sign up at LongStories.ai
  2. Go to your Dashboard
  3. Navigate to the API section
  4. Generate a new API key

Make Your First Request

Generate your first video with a simple POST request:
curl -X POST 'https://longstories.ai/api/v1/short' \
-H 'Content-Type: application/json' \
-H 'x-api-key: your-api-key' \
-d '{
  "prompt": "Create a video about the benefits of meditation",
  "scriptConfig": {
    "style": "engaging_conversational"
  },
  "imageConfig": {
    "model": "flux_schnell"
  }
}'
This will return a response with your generation run ID:
{
  "data": {
    "id": "run_rgncvakhqks9in7rdma2o"
  },
  "requestId": "472913f0-c717-4a59-898f-ea404e5978fc"
}

Check Generation Status

Monitor the status of your video generation:
curl 'https://longstories.ai/api/v1/short?runId=run_rgncvakhqks9in7rdma2o' \
-H 'x-api-key: your-api-key'
Response when complete:
{
  "data": {
    "status": "COMPLETED",
    "isCompleted": true,
    "isSuccess": true,
    "output": {
      "url": "https://s3.us-east-1.amazonaws.com/remotionlambda-useast1-hz34hfca77/renders/hvcugxdic1/out.mp4",
      "size": 5907614
    },
    "error": null
  },
  "requestId": "472913f0-c717-4a59-898f-ea404e5978fc"
}

Next Steps

  1. Explore the API Reference for all available options
  2. Learn about Error Handling for robust implementations
  3. Check out our Examples for common use cases
  4. Join our Discord community

Code Examples

JavaScript/TypeScript

async function generateVideo(prompt: string) {
  const response = await fetch('https://longstories.ai/api/v1/short', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': 'your-api-key'
    },
    body: JSON.stringify({
      prompt,
      scriptConfig: {
        style: 'educational'
      },
      imageConfig: {
        model: 'flux_schnell'
      }
    })
  });

  const { data } = await response.json();
  return data.id;
}

async function checkStatus(runId: string) {
  const response = await fetch(`https://longstories.ai/api/v1/short?runId=${runId}`, {
    headers: {
      'x-api-key': 'your-api-key'
    }
  });

  const { data } = await response.json();
  return data;
}

// Usage
const runId = await generateVideo('Create a video about the benefits of meditation');
console.log('Generation started:', runId);

// Poll for status
const checkInterval = setInterval(async () => {
  const status = await checkStatus(runId);
  console.log('Status:', status.status);
  
  if (status.isCompleted) {
    if (status.isSuccess) {
      console.log('Video URL:', status.output.url);
    } else {
      console.log('Generation failed:', status.error?.message);
    }
    clearInterval(checkInterval);
  }
}, 5000);

Python

import requests
import time

API_KEY = 'your-api-key'
BASE_URL = 'https://longstories.ai/api/v1'

def generate_video(prompt: str) -> str:
    response = requests.post(
        f'{BASE_URL}/short',
        headers={
            'Content-Type': 'application/json',
            'x-api-key': API_KEY
        },
        json={
            'prompt': prompt,
            'scriptConfig': {
                'style': 'educational'
            },
            'imageConfig': {
                'model': 'flux_schnell'
            }
        }
    )
    data = response.json()['data']
    return data['id']

def check_status(run_id: str) -> dict:
    response = requests.get(
        f'{BASE_URL}/short',
        params={'runId': run_id},
        headers={'x-api-key': API_KEY}
    )
    return response.json()['data']

# Usage
run_id = generate_video('Create a video about the benefits of meditation')
print(f'Generation started: {run_id}')

# Poll for status
while True:
    status = check_status(run_id)
    print(f'Status: {status["status"]}')
    
    if status['isCompleted']:
        if status['isSuccess']:
            print(f'Video URL: {status["output"]["url"]}')
        else:
            print(f'Generation failed: {status.get("error", {}).get("message")}')
        break
        
    time.sleep(5)

Tips for Success

  1. Start Simple: Begin with basic prompts and default settings
  2. Be Specific: Provide clear, detailed prompts for better results
  3. Handle Errors: Implement proper error handling and retries
  4. Monitor Status: Poll the status endpoint at reasonable intervals
  5. Test Different Styles: Experiment with different script and image styles