Official Go SDK for Apiframe - The ultimate platform for AI image and video generation APIs.
- 🎨 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
go get github.com/apiframe-ai/apiframe-go-sdkpackage 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)
}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)
})The original Midjourney API with comprehensive features.
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
})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 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
})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'
})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",
})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'
})Upscale with Subtle or Creative mode.
task, err := client.Midjourney.UpscaleAlt(apiframe.MidjourneyUpscaleAltParams{
ParentTaskID: "upscale1x_task_id",
Type: "subtle", // 'subtle' or 'creative'
})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
})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",
})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
})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'
})Writes four example prompts based on an image.
task, err := client.Midjourney.Describe(apiframe.MidjourneyDescribeParams{
ImageURL: "https://example.com/image.jpg",
})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'
})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",
})Get the seed of a generated image.
task, err := client.Midjourney.Seed(apiframe.MidjourneySeedParams{
TaskID: "original_task_id",
})The Pro Midjourney API with Fast & Turbo modes.
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 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'
})Create variations with strong/subtle control.
task, err := client.MidjourneyAlt.Vary(apiframe.MidjourneyAltVaryParams{
ParentTaskID: "parent_task_id",
Index: "1",
Type: "subtle", // 'subtle' or 'strong'
})Variations(params)- Generate 4 variations of an imagePan(params)- Pan in a specific directionZoom(params)- Zoom out from an imageGetGeneration(generationID)- Get generation infoGetAccountInfo()- Get Pro API account info
// 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{...})// 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,
})// 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",
})// 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",
})// 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,
})// 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)// 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",
})// 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)// 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},
})General task management methods.
Get the result/status of a submitted task.
task, err := client.Tasks.Get(taskID)
fmt.Printf("Status: %s\n", task.Status)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)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)
})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)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
}You can set your API key using an environment variable:
export APIFRAME_API_KEY=your_api_key_hereThen in your code:
import "os"
client, err := apiframe.NewClient(apiframe.Config{
APIKey: os.Getenv("APIFRAME_API_KEY"),
})Check the /examples directory for complete examples:
quickstart/- Quick start examplemidjourney/- Midjourney Original API usageflux/- Flux AI image generationluma_video/- Luma video generationsuno_music/- Suno music generationmedia_upload/- Media upload and usagecomprehensive/- All features demo
To run an example:
cd examples/quickstart
export APIFRAME_API_KEY=your_api_key
go run main.go- Go 1.21 or higher
- An Apiframe API key (get one at apiframe.ai)
For detailed API documentation, visit docs.apiframe.ai
- Documentation: docs.apiframe.ai
- GitHub Issues: github.com/apiframe-ai/apiframe-go-sdk/issues
MIT License - see LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Made with ❤️ by the Apiframe team