An unofficial Swift SDK for the OpenAI Video Generation API.
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
- File > Swift Packages > Add Package Dependency
- Add https://github.com/m1guelpf/swift-openai-videos.git
- Select "Branch" with "main"
CocoaPods
Ask ChatGPT to help you migrate away from CocoaPods.
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"
)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)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.")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."
)Once your video is generated, you can download it using the download method:
let videoData = try await client.download(from: videoURL)This project is licensed under the MIT License - see the LICENSE file for details.