Skip to content

About

Official Go SDK for Apiframe - AI image and video generation APIs (Midjourney, Flux, Luma, Suno, Runway, and more)

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apiframe Go SDK

Official Go SDK for Apiframe - The ultimate platform for AI image and video generation APIs.

Go Reference License: MIT

Features

  • 🎨 Midjourney API (Original) - Generate, upscale, vary, blend, inpaint, face swap
  • 🚀 Midjourney Pro API - Fast & Turbo modes, better stability
  • ⚡ Flux AI - Fast and high-quality image generation
  • 🎭 Ideogram - Creative image generation with text rendering
  • 🎬 Luma AI - Text and image to video generation
  • 🎵 Suno AI - AI music generation
  • 🎶 Udio AI - Advanced music creation
  • 🎥 Runway ML - Gen-3 video generation
  • 🎪 Kling AI - Video generation and manipulation
  • 📸 AI Photos - Headshots, face swap, and photo enhancement
  • 📤 Media Upload - Upload and manage media files

Installation

go get github.com/apiframe-ai/apiframe-go-sdk

Quick Start

package main

import (
	"fmt"
	"log"
	"os"

	"github.com/apiframe-ai/apiframe-go-sdk"
)

func main() {
	// Create a new Apiframe client
	client, err := apiframe.NewClient(apiframe.Config{
		APIKey: os.Getenv("APIFRAME_API_KEY"),
	})
	if err != nil {
		log.Fatal(err)
	}

	// Create an image generation task
	task, err := client.Midjourney.Imagine(apiframe.MidjourneyImagineParams{
		Prompt:      "a serene mountain landscape at sunset, photorealistic",
		AspectRatio: "16:9",
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Task created: %s\n", task.ID)

	// Wait for completion with progress updates
	result, err := client.Tasks.WaitFor(task.ID, &apiframe.WaitForOptions{
		OnProgress: func(progress int) {
			fmt.Printf("Progress: %d%%\n", progress)
		},
	})
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Images ready: %v\n", result.ImageURLs)
}

API Reference

Configuration

client, err := apiframe.NewClient(apiframe.Config{
	APIKey:  "your_api_key",                    // Required: Your Apiframe API key
	BaseURL: "https://api.apiframe.ai",         // Optional: Custom API endpoint
	Timeout: 300000,                            // Optional: Request timeout in ms (default: 300000)
})

Midjourney (Original API)

The original Midjourney API with comprehensive features.

Imagine

Create a new image generation task.

task, err := client.Midjourney.Imagine(apiframe.MidjourneyImagineParams{
	Prompt:        "a serene mountain landscape",
	AspectRatio:   "16:9",
	WebhookURL:    "https://your-domain.com/webhook",    // Optional
	WebhookSecret: "your-secret",                         // Optional
})

ImagineVideo

Generate videos using a text prompt and an image URL.

task, err := client.Midjourney.ImagineVideo(apiframe.MidjourneyImagineVideoParams{
	Prompt:   "cinematic mountain landscape",
	ImageURL: "https://example.com/start-frame.jpg",
	Motion:   "high", // Optional: 'low' or 'high'
})

Reroll

Reroll to create new images from a previous Imagine task.

task, err := client.Midjourney.Reroll(apiframe.MidjourneyRerollParams{
	ParentTaskID: "original_task_id",
	Prompt:       "optional new prompt", // Optional
})

Variations

Create 4 new variations of one of the 4 generated images.

task, err := client.Midjourney.Variations(apiframe.MidjourneyVariationsParams{
	ParentTaskID: "original_task_id",
	Index:        "1", // '1', '2', '3', '4', 'strong', or 'subtle'
})

FaceSwap

Swap the face on a target image with the face on a provided image.

task, err := client.Midjourney.FaceSwap(apiframe.MidjourneyFaceSwapParams{
	TargetImageURL: "https://example.com/target.jpg",
	SwapImageURL:   "https://example.com/face.jpg",
})

Upscale1x

Upscale one of the 4 generated images to get a single image.

task, err := client.Midjourney.Upscale1x(apiframe.MidjourneyUpscale1xParams{
	ParentTaskID: "original_task_id",
	Index:        "1", // '1', '2', '3', or '4'
})

UpscaleAlt

Upscale with Subtle or Creative mode.

task, err := client.Midjourney.UpscaleAlt(apiframe.MidjourneyUpscaleAltParams{
	ParentTaskID: "upscale1x_task_id",
	Type:         "subtle", // 'subtle' or 'creative'
})

UpscaleHighres

Upscale any image to higher resolution (2x or 4x).

task, err := client.Midjourney.UpscaleHighres(apiframe.MidjourneyUpscaleHighresParams{
	ParentTaskID: "task_id", // Or use ImageURL instead
	Type:         "2x",      // '2x' or '4x'
	Index:        "1",       // Optional: only if it's a 4 generated images task
})

Inpaint

Redraw a selected area of an image (Vary Region).

task, err := client.Midjourney.Inpaint(apiframe.MidjourneyInpaintParams{
	ParentTaskID: "upscale1x_task_id",
	Mask:         "base64_encoded_mask_image",
	Prompt:       "a red sports car",
})

Outpaint

Enlarges an image's canvas beyond its original size (Zoom Out).

task, err := client.Midjourney.Outpaint(apiframe.MidjourneyOutpaintParams{
	ParentTaskID: "upscale1x_task_id",
	ZoomRatio:    1.5, // 1.5, 2, or 1 for custom zoom
	AspectRatio:  "1:1",
	Prompt:       "mountain landscape", // Optional
})

Pan

Broadens the image canvas in a specific direction.

task, err := client.Midjourney.Pan(apiframe.MidjourneyPanParams{
	ParentTaskID: "upscale1x_task_id",
	Direction:    "up", // 'up', 'down', 'left', or 'right'
})

Describe

Writes four example prompts based on an image.

task, err := client.Midjourney.Describe(apiframe.MidjourneyDescribeParams{
	ImageURL: "https://example.com/image.jpg",
})

Blend

Blend multiple images into one image (2-5 images).

task, err := client.Midjourney.Blend(apiframe.MidjourneyBlendParams{
	ImageURLs: []string{
		"https://example.com/image1.jpg",
		"https://example.com/image2.jpg",
	},
	Dimension: "square", // 'square', 'portrait', or 'landscape'
})

Shorten

Analyzes your prompt and suggests optimizations.

task, err := client.Midjourney.Shorten(apiframe.MidjourneyShortenParams{
	Prompt: "a very beautiful and amazing sunset over the mountains with clouds",
})

Seed

Get the seed of a generated image.

task, err := client.Midjourney.Seed(apiframe.MidjourneySeedParams{
	TaskID: "original_task_id",
})

Midjourney Pro API (MidjourneyAlt)

The Pro Midjourney API with Fast & Turbo modes.

Imagine

Create a new image with Pro API (supports Fast and Turbo modes).

task, err := client.MidjourneyAlt.Imagine(apiframe.MidjourneyAltImagineParams{
	Prompt: "a serene mountain landscape",
	Mode:   "turbo", // 'fast' or 'turbo'
})

Upscale

Upscale a specific image from a Pro API generation.

task, err := client.MidjourneyAlt.Upscale(apiframe.MidjourneyAltUpscaleParams{
	ParentTaskID: "parent_task_id",
	Index:        "1",
	Type:         "subtle", // 'subtle' or 'creative'
})

Vary

Create variations with strong/subtle control.

task, err := client.MidjourneyAlt.Vary(apiframe.MidjourneyAltVaryParams{
	ParentTaskID: "parent_task_id",
	Index:        "1",
	Type:         "subtle", // 'subtle' or 'strong'
})

Other Pro API Methods

  • Variations(params) - Generate 4 variations of an image
  • Pan(params) - Pan in a specific direction
  • Zoom(params) - Zoom out from an image
  • GetGeneration(generationID) - Get generation info
  • GetAccountInfo() - Get Pro API account info

Flux

// Generate with Flux Pro
width := 1024
height := 1024
steps := 50
guidance := 7.5

task, err := client.Flux.Generate(apiframe.FluxGenerateParams{
	Model:    "flux-pro", // 'flux-schnell', 'flux-pro', 'flux-dev', 'flux-pro-1.1', 'flux-pro-1.1-ultra'
	Prompt:   "a futuristic cityscape",
	Width:    &width,
	Height:   &height,
	Steps:    &steps,
	Guidance: &guidance,
})

// Convenience methods
task, err := client.Flux.GeneratePro(apiframe.FluxGenerateParams{...})
task, err := client.Flux.GenerateDev(apiframe.FluxGenerateParams{...})
task, err := client.Flux.GenerateSchnell(apiframe.FluxGenerateParams{...})

Ideogram

// Generate image
task, err := client.Ideogram.Generate(apiframe.IdeogramGenerateParams{
	Prompt:      "a logo design",
	AspectRatio: "ASPECT_1_1",
	StyleType:   "DESIGN",
})

// Upscale image
task, err := client.Ideogram.Upscale(apiframe.IdeogramUpscaleParams{
	ImageURL:    "https://...",
	Prompt:      "enhance this image",
	Resemblance: 80,
	Detail:      &detail,
})

// Describe image
task, err := client.Ideogram.Describe(apiframe.IdeogramDescribeParams{
	ImageURL: "https://...",
})

// Remix (image-to-image)
task, err := client.Ideogram.Remix(apiframe.IdeogramRemixParams{
	ImageURL:    "https://...",
	Prompt:      "transform this image...",
	ImageWeight: 70,
})

Luma AI (Video)

// Generate video from text prompt
enhancePrompt := true
loop := false

task, err := client.Luma.Generate(apiframe.LumaGenerateParams{
	Prompt:        "a serene beach with waves",
	AspectRatio:   "16:9",
	EnhancePrompt: &enhancePrompt,
	Loop:          &loop,
})

// Generate with start and end images
task, err := client.Luma.Generate(apiframe.LumaGenerateParams{
	Prompt:      "a smooth transition",
	ImageURL:    "https://start-image.jpg",
	EndImageURL: "https://end-image.jpg",
})

// Extend a previously generated video
task, err := client.Luma.Extend(apiframe.LumaExtendParams{
	ParentTaskID: "previous_task_id",
	Prompt:       "continue the scene with more action",
})

Suno AI (Music)

// Generate song with lyrics (creates TWO songs)
task, err := client.Suno.Generate(apiframe.SunoGenerateParams{
	Prompt: "an upbeat electronic track",
	Lyrics: "[Verse 1]\nDancing through the night...",
	Model:  "chirp-v4",
	Tags:   "electronic, dance, upbeat",
	Title:  "Digital Dreams",
})

// Generate lyrics only
task, err := client.Suno.GenerateLyrics(apiframe.SunoLyricsParams{
	Prompt: "a song about summer adventures",
})

// Upload audio
task, err := client.Suno.Upload(apiframe.SunoUploadParams{
	AudioURL: "https://your-audio-url.mp3",
})

// Extend a song
fromUpload := true
task, err := client.Suno.Extend(apiframe.SunoExtendParams{
	SongID:     "song_id",
	ContinueAt: 30,
	FromUpload: &fromUpload,
	Prompt:     "continue with more energy",
})

Udio AI (Music)

// Generate music (creates TWO songs)
promptStrength := 0.8
task, err := client.Udio.Generate(apiframe.UdioGenerateParams{
	Prompt:         "a calm ambient soundtrack",
	Lyrics:         "Verse 1: Under the stars...",
	Model:          "udio32-v1.5",
	Tags:           "ambient, calm, instrumental",
	PromptStrength: &promptStrength,
})

Runway ML (Video)

// Generate video
duration := 10
task, err := client.Runway.Generate(apiframe.RunwayGenerateParams{
	Prompt:         "a drone shot flying over mountains",
	GenerationType: "text2video",
	Model:          "gen3",
	AspectRatio:    "16:9",
	Duration:       &duration,
})

// Convenience methods
task, err := client.Runway.TextToVideo("prompt", "16:9", "gen3", 5)
task, err := client.Runway.ImageToVideo("image_url", "prompt", "gen3", 10)
task, err := client.Runway.VideoToVideo("video_url", "prompt", "gen3", 5)

Kling AI (Video)

// Generate video
duration := 10
task, err := client.Kling.Generate(apiframe.KlingGenerateParams{
	Prompt:         "a time-lapse of a flower blooming",
	GenerationType: "text2video",
	Model:          "kling-v1-5",
	Mode:           "pro",
	AspectRatio:    "16:9",
	Duration:       &duration,
})

// Convenience methods
task, err := client.Kling.TextToVideo("prompt", "16:9", "kling-v1-5", 10)
task, err := client.Kling.ImageToVideo("image_url", "prompt", "kling-v1-5", "pro", 5)

// Virtual Try On
task, err := client.Kling.Tryon(apiframe.KlingTryonParams{
	HumanImageURL: "https://person-image.jpg",
	ClothImageURL: "https://clothing-image.jpg",
	Model:         "kolors-virtual-try-on-v1-5",
})

AI Photos

// Step 1: Upload 10-30 images for training
task, err := client.AIPhotos.Upload(apiframe.AIPhotosUploadParams{
	Images:    []string{"base64_1", "base64_2", "..."}, // 10-30 images
	Ethnicity: "white",
	Gender:    "male",
	Age:       30,
})

uploadResult, err := client.Tasks.WaitFor(task.ID, nil)

// Step 2: Train AI on the subject
trainTask, err := client.AIPhotos.Train(apiframe.AIPhotosTrainParams{
	TrainingImagesID: task.ID,
	TriggerWord:      "TOKMSN",
})

trainResult, err := client.Tasks.WaitFor(trainTask.ID, nil)

// Step 3: Generate photos
generateTask, err := client.AIPhotos.Generate(apiframe.AIPhotosGenerateParams{
	TrainingID:     trainTask.ID,
	Prompt:         "a portrait of TOKMSN wearing a suit",
	AspectRatio:    "1:1",
	NumberOfImages: "4",
})

result, err := client.Tasks.WaitFor(generateTask.ID, nil)

Media Upload

// Upload image from file
upload, err := client.Media.Upload("./path/to/image.jpg", nil)
fmt.Println("Uploaded:", upload.ImageURL)

// Upload image from bytes
imageBytes, _ := os.ReadFile("image.jpg")
upload, err := client.Media.Upload("", imageBytes)

// Upload audio
audioUpload, err := client.Media.UploadAudio("./path/to/audio.mp3", nil)
fmt.Println("Uploaded audio:", audioUpload.AudioURL)

// Use uploaded media
task, err := client.Midjourney.Blend(apiframe.MidjourneyBlendParams{
	ImageURLs: []string{upload.ImageURL, anotherURL},
})

Tasks

General task management methods.

Get

Get the result/status of a submitted task.

task, err := client.Tasks.Get(taskID)
fmt.Printf("Status: %s\n", task.Status)

GetMany

Get the results/statuses of multiple tasks (min 2, max 20).

result, err := client.Tasks.GetMany([]string{"task_id_1", "task_id_2"})
fmt.Printf("Tasks: %v\n", result.Tasks)

WaitFor

Wait for a task to complete with progress tracking.

result, err := client.Tasks.WaitFor(taskID, &apiframe.WaitForOptions{
	OnProgress: func(progress int) {
		fmt.Printf("Progress: %d%%\n", progress)
	},
	Interval: 3000,  // Polling interval in ms (default: 3000)
	Timeout:  300000, // Max wait time in ms (default: 300000)
})

GetAccountInfo

Get account details including credits, usage, plan, etc.

account, err := client.Tasks.GetAccountInfo()
fmt.Printf("Email: %s\n", account.Email)
fmt.Printf("Credits: %d\n", account.Credits)
fmt.Printf("Plan: %s\n", account.Plan)

Error Handling

import "github.com/apiframe-ai/apiframe-go-sdk"

task, err := client.Midjourney.Imagine(apiframe.MidjourneyImagineParams{
	Prompt: "...",
})
if err != nil {
	switch e := err.(type) {
	case *apiframe.AuthenticationError:
		fmt.Println("Invalid API key")
	case *apiframe.RateLimitError:
		fmt.Println("Rate limit exceeded")
	case *apiframe.TimeoutError:
		fmt.Println("Request timed out")
	case *apiframe.Error:
		fmt.Printf("API error: %s (status: %d)\n", e.Message, e.Status)
	default:
		fmt.Printf("Error: %v\n", err)
	}
	return
}

Environment Variables

You can set your API key using an environment variable:

export APIFRAME_API_KEY=your_api_key_here

Then in your code:

import "os"

client, err := apiframe.NewClient(apiframe.Config{
	APIKey: os.Getenv("APIFRAME_API_KEY"),
})

Examples

Check the /examples directory for complete examples:

  • quickstart/ - Quick start example
  • midjourney/ - Midjourney Original API usage
  • flux/ - Flux AI image generation
  • luma_video/ - Luma video generation
  • suno_music/ - Suno music generation
  • media_upload/ - Media upload and usage
  • comprehensive/ - All features demo

To run an example:

cd examples/quickstart
export APIFRAME_API_KEY=your_api_key
go run main.go

Requirements

  • Go 1.21 or higher
  • An Apiframe API key (get one at apiframe.ai)

Documentation

For detailed API documentation, visit docs.apiframe.ai

Support

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Made with ❤️ by the Apiframe team

About

Official Go SDK for Apiframe - AI image and video generation APIs (Midjourney, Flux, Luma, Suno, Runway, and more)

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages