m1guelpf/swift-openai-videos
An unofficial Swift SDK for the [OpenAI Video Generation API](https://platform.openai.com/docs/guides/video-generation).
Installation
<details>
<summary> Swift Package Manager </summary>
Add the following to your Package.swift:
dependencies: [
.package(url: "https://github.com/m1guelpf/swift-openai-videos.git", .branch("main"))
]</details> <details>
<summary>Installing through XCode</summary>
- File > Swift Packages > Add Package Dependency
- Add https://github.com/m1guelpf/swift-openai-videos.git
- Select "Branch" with "main"
</details>
<details>
<summary>CocoaPods</summary>
Ask ChatGPT to help you migrate away from CocoaPods.
</details>
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.
Package Metadata
Repository: m1guelpf/swift-openai-videos
Default branch: main
README: README.md