Skip to content

m1guelpf/swift-openai-videos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI Videos API

Swift Version GitHub license

An unofficial Swift SDK for the OpenAI Video Generation API.

Installation

Swift Package Manager

Add the following to your Package.swift:

dependencies: [
	.package(url: "https://github.com/m1guelpf/swift-openai-videos.git", .branch("main"))
]
Installing through XCode
CocoaPods

Ask ChatGPT to help you migrate away from CocoaPods.

Getting started 🚀

import VideosAPI

let client = VideosAPI(authToken: OPENAI_API_KEY)

let response = try await client.create(prompt: "A cat playing chess")

let response = try await client.remix(
    id: response.id,
    prompt: "Change the color of the sky"
)

Architecture

Creating a new instance

To interact with the Videos API, create a new instance of VideosAPI with your API key:

let client = VideosAPI(authToken: YOUR_OPENAI_API_TOKEN)

Optionally, you can provide an Organization ID and/or project ID:

let client = VideosAPI(
	authToken: YOUR_OPENAI_API_KEY,
	organizationId: YOUR_ORGANIZATION_ID,
	projectId: YOUR_PROJECT_ID
)

For more advanced use cases like connecting to a custom server, you can customize the URLRequest used to connect to the API:

let urlRequest = URLRequest(url: MY_CUSTOM_ENDPOINT)
urlRequest.addValue("Bearer \(YOUR_API_KEY)", forHTTPHeaderField: "Authorization")

let client = VideosAPI(connectingTo: urlRequest)

Creating Videos

To generate new videos, call the create method:

let response = try await client.create(prompt: "A video of a cool cat on a motorcycle in the night.")

Editing Videos

To edit an existing video, call the remix method, passing the video ID to remix and a new prompt:

let response = try await client.remix(
    id: videoId,
    prompt: "Change the background to a beach."
)

Downloading Videos

Once your video is generated, you can download it using the download method:

let videoData = try await client.download(from: videoURL)

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

An unofficial Swift SDK for the OpenAI Video Generation API.

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Languages