abstrakt
Models
Featured
Sora 2 Pro
Featured

Sora 2 Pro

OpenAI's most advanced video generation model with photorealistic output and complex scene understanding.

Veo 3.1
New

Veo 3.1

Google DeepMind's flagship video model with exceptional motion consistency and cinematic quality.

Kling 2.6
Popular

Kling 2.6

Latest Kling model with enhanced character consistency, longer duration support, and improved physics.

Active

100+ AI Models

Access the best AI models from multiple providers through one unified API. Switch models without changing code.

Browse all models
Tools
Featured
AI Image Generator
Popular

AI Image Generator

Create stunning images from text descriptions using FLUX, Stable Diffusion, and more.

Text to Video
New

Text to Video

Transform your ideas into cinematic AI videos with Sora, Veo, and Kling models.

Text to Speech

Text to Speech

Convert text to natural-sounding speech with 30+ voices and emotional expression.

Active

20+ AI Tools

Ready-to-use tools for image, video, and audio generation. No code required — just upload and create.

Explore all tools
Tutorials
Featured
Build Your First AI App
Start Here

Build Your First AI App

Your first AI generation in 5 minutes. Set up your API key and create your first image.

Text-to-Image Masterclass

Text-to-Image Masterclass

Master prompting techniques, model selection, and advanced settings for stunning results.

Text-to-Video Fundamentals

Text-to-Video Fundamentals

Learn to create cinematic AI videos with proper motion, pacing, and storytelling.

Active

Learn AI Generation

Step-by-step guides to master AI image, video, and audio creation. From beginner to advanced.

View all tutorials
Sandbox
Docs
TutorialsGetting StartedBuilding your first GenAI App
BeginnerUpdated Dec 15, 2025

Building your first GenAI App

A complete walkthrough of setting up your environment, API keys, and making your first request to the image generation model using Python.

SC
Sarah Chen
Developer Advocate
5 min read

Introduction

Generative AI has opened up new frontiers for application developers. In this guide, we will build a simple command-line interface (CLI) tool that takes a text prompt from the user and generates a high-quality image using the Abstrakt API. By the end of this tutorial, you will understand authentication, request formatting, and handling image responses.

PrerequisitesMake sure you have Python 3.8+ installed and an active API key from the dashboard. If you don't have a key, sign up here.

Setting up the Environment

First, let's create a new directory for our project and set up a virtual environment to keep our dependencies isolated.

$ mkdir genai-app
$ cd genai-app
$ python3 -m venv venv
$ source venv/bin/activate
$ pip install requests python-dotenv

Create the Configuration

Create a .env file in your project root to store your API key securely:

ABSTRAKT_API_KEY=your_api_key_here

The Implementation

Create a file named main.py. We'll start by importing the necessary libraries and initializing the client. We recommend using environment variables for your API key to avoid hardcoding secrets.

python
import os
import requests
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

def generate_image(prompt):
    """Generate an image from a text prompt."""
    api_key = os.getenv("ABSTRAKT_API_KEY")
    
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    
    payload = {
        "input": {
            "prompt": prompt,
            "image_size": {"width": 1024, "height": 1024},
            "num_images": 1
        }
    }
    
    print(f"Generating image for: {prompt}...")
    
    response = requests.post(
        "https://api.abstrakt.one/v1/models/flux-schnell/run",
        headers=headers,
        json=payload
    )
    
    result = response.json()
    
    if result.get("status") == "completed":
        return result["result"]["items"][0]["url"]
    else:
        raise Exception(f"Generation failed: {result}")

if __name__ == "__main__":
    prompt = "A futuristic city with flying cars, cyberpunk style, neon lights"
    url = generate_image(prompt)
    print(f"Image generated successfully: {url}")

Testing the Application

Run the script from your terminal. If the request is successful, you will see a URL printed to the console. This URL points to your generated image stored on our CDN.

$ python main.py
Generating image for: A futuristic city with flying cars...
Image generated successfully: https://cdn.abstrakt.one/images/...

Downloading the Image

Let's enhance our script to download and save the image locally:

python
def download_image(url, filename):
    """Download an image from URL and save locally."""
    response = requests.get(url)
    with open(filename, "wb") as f:
        f.write(response.content)
    print(f"Image saved to {filename}")

# Add to main
if __name__ == "__main__":
    prompt = "A futuristic city with flying cars, cyberpunk style"
    url = generate_image(prompt)
    download_image(url, "generated_image.png")

Next Steps

  • Explore adding negative prompts to refine the output
  • Implement a webhook handler for asynchronous processing
  • Try different models like FLUX Dev for higher quality
  • Add error handling and retry logic for production use
#python#quickstart#image-generation
NextPython SDK Setup
On This Page
  • Introduction
  • Setting up the Environment
  • Create the Configuration
  • The Implementation
  • Testing the Application
  • Downloading the Image
  • Next Steps
Related Guides
Python SDK Setup

Get the Python SDK installed and configured in under 5 minutes.

Text-to-Image Masterclass

Learn professional prompting techniques for stunning AI images.

Was this page helpful?

abstrakt
abstrakt

The unified abstraction layer for the next generation of AI applications. Build faster with any model.

Start Here+
  • Quickstart
  • Get API Key
  • Try Playground
  • View Pricing
Image Tools+
  • AI Image Generator
  • Image to Image
  • Remove Background
  • Image Upscaler
  • Object Remover
  • Style Transfer
  • Image Enhancer
  • AI Art Generator
Video Tools+
  • Text to Video
  • Image to Video
  • AI Video Generator
  • Video Upscaler
  • Video Enhancer
  • Frame Interpolation
Audio Tools+
  • Text to Speech
  • Speech to Text
  • AI Music Generator
  • Voice Cloning
  • Audio Enhancer
  • Sound Effects
Tutorials+
  • Getting Started
  • Image Generation
  • Video Generation
  • Audio Generation
  • Advanced Topics
  • AI Glossary
  • All Tutorials
Models+
  • FLUX Schnell
  • FLUX Dev
  • Fast SDXL
  • Stable Diffusion 3
  • MiniMax Video
  • Kling AI
  • Ideogram
  • More Models
Company+
  • About Us
  • Pricing
  • Documentation
  • Tutorials
  • Blog
  • Contact
  • Changelog
  • Status
  • Careers
  • Privacy Policy
  • Terms of Service
  • Cookie Policy

Image Tools

  • AI Image Generator
  • Image to Image
  • Remove Background
  • Image Upscaler
  • Object Remover
  • Style Transfer
  • Image Enhancer
  • AI Art Generator

Video Tools

  • Text to Video
  • Image to Video
  • AI Video Generator
  • Video Upscaler
  • Video Enhancer
  • Frame Interpolation

Audio Tools

  • Text to Speech
  • Speech to Text
  • AI Music Generator
  • Voice Cloning
  • Audio Enhancer
  • Sound Effects

Tutorials

  • Getting Started
  • Image Generation
  • Video Generation
  • Audio Generation
  • Advanced Topics
  • AI Glossary
  • All Tutorials

Start Here

  • Quickstart
  • Get API Key
  • Try Playground
  • View Pricing

Models

  • FLUX Schnell
  • FLUX Dev
  • Fast SDXL
  • Stable Diffusion 3
  • MiniMax Video
  • Kling AI
  • Ideogram
  • More Models

Company

  • About Us
  • Pricing
  • Documentation
  • Tutorials
  • Blog
  • Contact
  • Changelog
  • Status
  • Careers
  • Privacy Policy
  • Terms of Service
  • Cookie Policy
abstrakt

The unified abstraction layer for the next generation of AI applications.

© 2026 abstrakt. All rights reserved.

SYS.ONLINE|API.ACTIVE|v1.2.0