Skip to content

Commit 0a6582e

Browse files
authored
Add protocol method support for Video APIs (#772)
Add Videos API
1 parent 84fb83b commit 0a6582e

File tree

18 files changed

+13058
-9716
lines changed

18 files changed

+13058
-9716
lines changed

api/OpenAI.net8.0.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public class OpenAIClient {
3737
public virtual RealtimeClient GetRealtimeClient();
3838
[Experimental("OPENAI001")]
3939
public virtual VectorStoreClient GetVectorStoreClient();
40+
[Experimental("OPENAI001")]
41+
public virtual VideoClient GetVideoClient();
4042
}
4143
public class OpenAIClientOptions : ClientPipelineOptions {
4244
public Uri Endpoint { get; set; }
@@ -6815,4 +6817,31 @@ public enum VectorStoreStatus {
68156817
Completed = 2,
68166818
Expired = 3
68176819
}
6820+
}
6821+
namespace OpenAI.Videos {
6822+
[Experimental("OPENAI001")]
6823+
public class VideoClient {
6824+
protected VideoClient();
6825+
public VideoClient(ApiKeyCredential credential, OpenAIClientOptions options);
6826+
public VideoClient(ApiKeyCredential credential);
6827+
public VideoClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options);
6828+
public VideoClient(AuthenticationPolicy authenticationPolicy);
6829+
protected internal VideoClient(ClientPipeline pipeline, OpenAIClientOptions options);
6830+
public VideoClient(string apiKey);
6831+
[Experimental("OPENAI001")]
6832+
public Uri Endpoint { get; }
6833+
public ClientPipeline Pipeline { get; }
6834+
public virtual ClientResult CreateVideo(BinaryContent content, string contentType, RequestOptions options = null);
6835+
public virtual Task<ClientResult> CreateVideoAsync(BinaryContent content, string contentType, RequestOptions options = null);
6836+
public virtual ClientResult CreateVideoRemix(string videoId, BinaryContent content, string contentType, RequestOptions options = null);
6837+
public virtual Task<ClientResult> CreateVideoRemixAsync(string videoId, BinaryContent content, string contentType, RequestOptions options = null);
6838+
public virtual ClientResult DeleteVideo(string videoId, RequestOptions options = null);
6839+
public virtual Task<ClientResult> DeleteVideoAsync(string videoId, RequestOptions options = null);
6840+
public virtual ClientResult DownloadVideo(string videoId, string variant = null, RequestOptions options = null);
6841+
public virtual Task<ClientResult> DownloadVideoAsync(string videoId, string variant = null, RequestOptions options = null);
6842+
public virtual ClientResult GetVideo(string videoId, RequestOptions options = null);
6843+
public virtual Task<ClientResult> GetVideoAsync(string videoId, RequestOptions options = null);
6844+
public virtual ClientResult GetVideos(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6845+
public virtual Task<ClientResult> GetVideosAsync(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6846+
}
68186847
}

api/OpenAI.netstandard2.0.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class OpenAIClient {
2525
public virtual OpenAIResponseClient GetOpenAIResponseClient(string model);
2626
public virtual RealtimeClient GetRealtimeClient();
2727
public virtual VectorStoreClient GetVectorStoreClient();
28+
public virtual VideoClient GetVideoClient();
2829
}
2930
public class OpenAIClientOptions : ClientPipelineOptions {
3031
public Uri Endpoint { get; set; }
@@ -6007,4 +6008,29 @@ public enum VectorStoreStatus {
60076008
Completed = 2,
60086009
Expired = 3
60096010
}
6011+
}
6012+
namespace OpenAI.Videos {
6013+
public class VideoClient {
6014+
protected VideoClient();
6015+
public VideoClient(ApiKeyCredential credential, OpenAIClientOptions options);
6016+
public VideoClient(ApiKeyCredential credential);
6017+
public VideoClient(AuthenticationPolicy authenticationPolicy, OpenAIClientOptions options);
6018+
public VideoClient(AuthenticationPolicy authenticationPolicy);
6019+
protected internal VideoClient(ClientPipeline pipeline, OpenAIClientOptions options);
6020+
public VideoClient(string apiKey);
6021+
public Uri Endpoint { get; }
6022+
public ClientPipeline Pipeline { get; }
6023+
public virtual ClientResult CreateVideo(BinaryContent content, string contentType, RequestOptions options = null);
6024+
public virtual Task<ClientResult> CreateVideoAsync(BinaryContent content, string contentType, RequestOptions options = null);
6025+
public virtual ClientResult CreateVideoRemix(string videoId, BinaryContent content, string contentType, RequestOptions options = null);
6026+
public virtual Task<ClientResult> CreateVideoRemixAsync(string videoId, BinaryContent content, string contentType, RequestOptions options = null);
6027+
public virtual ClientResult DeleteVideo(string videoId, RequestOptions options = null);
6028+
public virtual Task<ClientResult> DeleteVideoAsync(string videoId, RequestOptions options = null);
6029+
public virtual ClientResult DownloadVideo(string videoId, string variant = null, RequestOptions options = null);
6030+
public virtual Task<ClientResult> DownloadVideoAsync(string videoId, string variant = null, RequestOptions options = null);
6031+
public virtual ClientResult GetVideo(string videoId, RequestOptions options = null);
6032+
public virtual Task<ClientResult> GetVideoAsync(string videoId, RequestOptions options = null);
6033+
public virtual ClientResult GetVideos(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6034+
public virtual Task<ClientResult> GetVideosAsync(long? limit = null, string order = null, string after = null, RequestOptions options = null);
6035+
}
60106036
}

examples/OpenAI.Examples.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net9.0</TargetFramework>
44

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using NUnit.Framework;
2+
using NUnit.Framework.Internal;
3+
using OpenAI.Videos;
4+
using System;
5+
using System.ClientModel;
6+
using System.Net.Http;
7+
using System.Text;
8+
using System.Text.Json;
9+
10+
namespace OpenAI.Examples;
11+
12+
// This example uses experimental APIs which are subject to change. To use experimental APIs,
13+
// please acknowledge their experimental status by suppressing the corresponding warning.
14+
#pragma warning disable OPENAI001
15+
16+
public partial class VideoExamples
17+
{
18+
[Test]
19+
public void Example01_VideoCreation()
20+
{
21+
// 1) Create the client
22+
VideoClient client = new(new ApiKeyCredential(Environment.GetEnvironmentVariable("OPENAI_API_KEY")));
23+
24+
// 2) Build the multipart/form-data payload with an explicit boundary
25+
var boundary = Guid.NewGuid().ToString();
26+
var contentType = $"multipart/form-data; boundary=\"{boundary}\"";
27+
using var multipart = new MultipartFormDataContent(boundary);
28+
29+
multipart.Add(new StringContent("sora-2", Encoding.UTF8, "text/plain"), "model");
30+
multipart.Add(new StringContent("A calico cat playing a piano on stage", Encoding.UTF8, "text/plain"), "prompt");
31+
32+
// 3) Get a stream for the multipart body
33+
using var bodyStream = multipart.ReadAsStream();
34+
35+
// 4) Send the request
36+
var createResult = client.CreateVideo(BinaryContent.Create(bodyStream), contentType);
37+
var createRaw = createResult.GetRawResponse().Content;
38+
39+
// 5) Parse the JSON response
40+
using var createdDoc = JsonDocument.Parse(createRaw);
41+
var id = createdDoc.RootElement.GetProperty("id").GetString();
42+
var status = createdDoc.RootElement.GetProperty("status").GetString();
43+
44+
Console.WriteLine($"CreateVideo => id: {id}, status: {status}");
45+
}
46+
}
47+
48+
#pragma warning restore OPENAI001
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using NUnit.Framework;
2+
using NUnit.Framework.Internal;
3+
using OpenAI.Videos;
4+
using System;
5+
using System.ClientModel;
6+
using System.Net.Http;
7+
using System.Text;
8+
using System.Text.Json;
9+
using System.Threading.Tasks;
10+
11+
namespace OpenAI.Examples;
12+
13+
// This example uses experimental APIs which are subject to change. To use experimental APIs,
14+
// please acknowledge their experimental status by suppressing the corresponding warning.
15+
#pragma warning disable OPENAI001
16+
17+
public partial class VideoExamples
18+
{
19+
[Test]
20+
public async Task Example01_VideoCreationAsync()
21+
{
22+
// 1) Create the client
23+
VideoClient client = new(new ApiKeyCredential(Environment.GetEnvironmentVariable("OPENAI_API_KEY")));
24+
25+
// 2) Build the multipart/form-data payload with an explicit boundary
26+
var boundary = Guid.NewGuid().ToString();
27+
var contentType = $"multipart/form-data; boundary=\"{boundary}\"";
28+
using var multipart = new MultipartFormDataContent(boundary);
29+
30+
multipart.Add(new StringContent("sora-2", Encoding.UTF8, "text/plain"), "model");
31+
multipart.Add(new StringContent("A calico cat playing a piano on stage", Encoding.UTF8, "text/plain"), "prompt");
32+
33+
// 3) Get a stream for the multipart body
34+
using var bodyStream = await multipart.ReadAsStreamAsync();
35+
36+
// 4) Send the request
37+
var createResult = await client.CreateVideoAsync(BinaryContent.Create(bodyStream), contentType);
38+
var createRaw = createResult.GetRawResponse().Content;
39+
40+
// 5) Parse the JSON response
41+
using var createdDoc = JsonDocument.Parse(createRaw);
42+
var id = createdDoc.RootElement.GetProperty("id").GetString();
43+
var status = createdDoc.RootElement.GetProperty("status").GetString();
44+
45+
Console.WriteLine($"CreateVideo => id: {id}, status: {status}");
46+
}
47+
}
48+
49+
#pragma warning restore OPENAI001

scripts/Export-Api.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ function Invoke-GenAPI {
272272
$content = $content -creplace "Realtime\.", ""
273273
$content = $content -creplace "Responses\.", ""
274274
$content = $content -creplace "VectorStores\.", ""
275+
$content = $content -creplace "Videos\.", ""
275276

276277
# Remove Diagnostics.DebuggerStepThrough attribute.
277278
$content = $content -creplace ".*Diagnostics.DebuggerStepThrough.*\n", ""

specification/base/typespec/common/models.tsp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,3 +468,12 @@ union ServiceTier {
468468
"flex",
469469
"scale",
470470
}
471+
472+
#suppress "@azure-tools/typespec-azure-core/no-enum" "Auto-suppressed warnings non-applicable rules during import."
473+
#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
474+
enum OrderEnum {
475+
#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
476+
asc,
477+
#suppress "@azure-tools/typespec-azure-core/documentation-required" "Auto-suppressed warnings non-applicable rules during import."
478+
desc,
479+
}

specification/base/typespec/main.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ import "./runs";
1919
import "./threads";
2020
import "./responses";
2121
import "./vector-stores";
22+
import "./videos";
2223
import "./uploads";
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import "./models.tsp";
2+
import "./operations.tsp";

0 commit comments

Comments
 (0)