Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial interface IUsageClient
/// Default Value: 1d
/// </param>
/// <param name="projectIds"></param>
/// <param name="apiKeyIds"></param>
/// <param name="groupBy"></param>
/// <param name="limit">
/// Default Value: 7
Expand All @@ -26,6 +27,7 @@ public partial interface IUsageClient
int? endTime = default,
global::tryAGI.OpenAI.UsageCostsBucketWidth? bucketWidth = default,
global::System.Collections.Generic.IList<string>? projectIds = default,
global::System.Collections.Generic.IList<string>? apiKeyIds = default,
global::System.Collections.Generic.IList<global::tryAGI.OpenAI.UsageCostsGroupByItem>? groupBy = default,
int? limit = default,
string? page = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public sealed partial class CostsResult
[global::System.Text.Json.Serialization.JsonPropertyName("project_id")]
public string? ProjectId { get; set; }

/// <summary>
///
/// </summary>
[global::System.Text.Json.Serialization.JsonPropertyName("api_key_id")]
public string? ApiKeyId { get; set; }

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
Expand All @@ -48,19 +54,22 @@ public sealed partial class CostsResult
/// </param>
/// <param name="lineItem"></param>
/// <param name="projectId"></param>
/// <param name="apiKeyId"></param>
#if NET7_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.SetsRequiredMembers]
#endif
public CostsResult(
global::tryAGI.OpenAI.CostsResultObject @object,
global::tryAGI.OpenAI.CostsResultAmount? amount,
string? lineItem,
string? projectId)
string? projectId,
string? apiKeyId)
{
this.Object = @object;
this.Amount = amount;
this.LineItem = lineItem;
this.ProjectId = projectId;
this.ApiKeyId = apiKeyId;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#nullable enable

namespace tryAGI.OpenAI
{
public sealed partial class CostsResultApiKeyId
{
/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerContext.
/// </summary>
public string ToJson(
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
this.GetType(),
jsonSerializerContext);
}

/// <summary>
/// Serializes the current instance to a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public string ToJson(
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Serialize(
this,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerContext.
/// </summary>
public static global::tryAGI.OpenAI.CostsResultApiKeyId? FromJson(
string json,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return global::System.Text.Json.JsonSerializer.Deserialize(
json,
typeof(global::tryAGI.OpenAI.CostsResultApiKeyId),
jsonSerializerContext) as global::tryAGI.OpenAI.CostsResultApiKeyId;
}

/// <summary>
/// Deserializes a JSON string using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::tryAGI.OpenAI.CostsResultApiKeyId? FromJson(
string json,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.Deserialize<global::tryAGI.OpenAI.CostsResultApiKeyId>(
json,
jsonSerializerOptions);
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerContext.
/// </summary>
public static async global::System.Threading.Tasks.ValueTask<global::tryAGI.OpenAI.CostsResultApiKeyId?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
return (await global::System.Text.Json.JsonSerializer.DeserializeAsync(
jsonStream,
typeof(global::tryAGI.OpenAI.CostsResultApiKeyId),
jsonSerializerContext).ConfigureAwait(false)) as global::tryAGI.OpenAI.CostsResultApiKeyId;
}

/// <summary>
/// Deserializes a JSON stream using the provided JsonSerializerOptions.
/// </summary>
#if NET8_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed. Use the overload that takes a JsonTypeInfo or JsonSerializerContext, or make sure all of the required types are preserved.")]
[global::System.Diagnostics.CodeAnalysis.RequiresDynamicCode("JSON serialization and deserialization might require types that cannot be statically analyzed and might need runtime code generation. Use System.Text.Json source generation for native AOT applications.")]
#endif
public static global::System.Threading.Tasks.ValueTask<global::tryAGI.OpenAI.CostsResultApiKeyId?> FromJsonStreamAsync(
global::System.IO.Stream jsonStream,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = null)
{
return global::System.Text.Json.JsonSerializer.DeserializeAsync<global::tryAGI.OpenAI.CostsResultApiKeyId?>(
jsonStream,
jsonSerializerOptions);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#nullable enable

namespace tryAGI.OpenAI
{
/// <summary>
///
/// </summary>
public sealed partial class CostsResultApiKeyId
{

/// <summary>
/// Additional properties that are not explicitly defined in the schema
/// </summary>
[global::System.Text.Json.Serialization.JsonExtensionData]
public global::System.Collections.Generic.IDictionary<string, object> AdditionalProperties { get; set; } = new global::System.Collections.Generic.Dictionary<string, object>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace tryAGI.OpenAI
/// </summary>
public enum UsageCostsGroupByItem
{
/// <summary>
///
/// </summary>
ApiKeyId,
/// <summary>
///
/// </summary>
Expand All @@ -30,6 +34,7 @@ public static string ToValueString(this UsageCostsGroupByItem value)
{
return value switch
{
UsageCostsGroupByItem.ApiKeyId => "api_key_id",
UsageCostsGroupByItem.LineItem => "line_item",
UsageCostsGroupByItem.ProjectId => "project_id",
_ => throw new global::System.ArgumentOutOfRangeException(nameof(value), value, null),
Expand All @@ -42,6 +47,7 @@ public static string ToValueString(this UsageCostsGroupByItem value)
{
return value switch
{
"api_key_id" => UsageCostsGroupByItem.ApiKeyId,
"line_item" => UsageCostsGroupByItem.LineItem,
"project_id" => UsageCostsGroupByItem.ProjectId,
_ => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ partial void PrepareCostsArguments(
ref int? endTime,
ref global::tryAGI.OpenAI.UsageCostsBucketWidth? bucketWidth,
global::System.Collections.Generic.IList<string>? projectIds,
global::System.Collections.Generic.IList<string>? apiKeyIds,
global::System.Collections.Generic.IList<global::tryAGI.OpenAI.UsageCostsGroupByItem>? groupBy,
ref int? limit,
ref string? page);
Expand All @@ -41,6 +42,7 @@ partial void PrepareCostsRequest(
int? endTime,
global::tryAGI.OpenAI.UsageCostsBucketWidth? bucketWidth,
global::System.Collections.Generic.IList<string>? projectIds,
global::System.Collections.Generic.IList<string>? apiKeyIds,
global::System.Collections.Generic.IList<global::tryAGI.OpenAI.UsageCostsGroupByItem>? groupBy,
int? limit,
string? page);
Expand All @@ -62,6 +64,7 @@ partial void ProcessCostsResponseContent(
/// Default Value: 1d
/// </param>
/// <param name="projectIds"></param>
/// <param name="apiKeyIds"></param>
/// <param name="groupBy"></param>
/// <param name="limit">
/// Default Value: 7
Expand All @@ -75,6 +78,7 @@ partial void ProcessCostsResponseContent(
int? endTime = default,
global::tryAGI.OpenAI.UsageCostsBucketWidth? bucketWidth = default,
global::System.Collections.Generic.IList<string>? projectIds = default,
global::System.Collections.Generic.IList<string>? apiKeyIds = default,
global::System.Collections.Generic.IList<global::tryAGI.OpenAI.UsageCostsGroupByItem>? groupBy = default,
int? limit = default,
string? page = default,
Expand All @@ -89,6 +93,7 @@ partial void ProcessCostsResponseContent(
endTime: ref endTime,
bucketWidth: ref bucketWidth,
projectIds: projectIds,
apiKeyIds: apiKeyIds,
groupBy: groupBy,
limit: ref limit,
page: ref page);
Expand Down Expand Up @@ -123,6 +128,7 @@ partial void ProcessCostsResponseContent(
.AddOptionalParameter("end_time", endTime?.ToString())
.AddOptionalParameter("bucket_width", bucketWidth?.ToValueString())
.AddOptionalParameter("project_ids", projectIds, delimiter: ",", explode: true)
.AddOptionalParameter("api_key_ids", apiKeyIds, delimiter: ",", explode: true)
.AddOptionalParameter("group_by", groupBy, selector: static x => x.ToValueString(), delimiter: ",", explode: true)
.AddOptionalParameter("limit", limit?.ToString())
.AddOptionalParameter("page", page)
Expand Down Expand Up @@ -171,6 +177,7 @@ partial void ProcessCostsResponseContent(
endTime: endTime,
bucketWidth: bucketWidth,
projectIds: projectIds,
apiKeyIds: apiKeyIds,
groupBy: groupBy,
limit: limit,
page: page);
Expand Down
79 changes: 77 additions & 2 deletions src/libs/tryAGI.OpenAI/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14266,6 +14266,64 @@ paths:
curl https://api.openai.com/v1/organization/audit_logs \
-H "Authorization: Bearer $OPENAI_ADMIN_KEY" \
-H "Content-Type: application/json"
node.js: >-
import OpenAI from 'openai';


const client = new OpenAI({
adminAPIKey: process.env['OPENAI_ADMIN_KEY'], // This is the default and can be omitted
});


// Automatically fetches more pages as needed.

for await (const auditLogListResponse of
client.admin.organization.auditLogs.list()) {
console.log(auditLogListResponse.id);
}
python: |-
import os
from openai import OpenAI

client = OpenAI(
admin_api_key=os.environ.get("OPENAI_ADMIN_KEY"), # This is the default and can be omitted
)
page = client.admin.organization.audit_logs.list()
page = page.data[0]
print(page.id)
go: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/openai/openai-go\"\n\t\"github.com/openai/openai-go/option\"\n)\n\nfunc main() {\n\tclient := openai.NewClient(\n\t\toption.WithAdminAPIKey(\"My Admin API Key\"),\n\t)\n\tpage, err := client.Admin.Organization.AuditLogs.List(context.TODO(), openai.AdminOrganizationAuditLogListParams{})\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", page)\n}\n"
java: >-
package com.openai.example;


import com.openai.client.OpenAIClient;

import com.openai.client.okhttp.OpenAIOkHttpClient;

import
com.openai.models.admin.organization.auditlogs.AuditLogListPage;

import
com.openai.models.admin.organization.auditlogs.AuditLogListParams;


public final class Main {
private Main() {}

public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();

AuditLogListPage page = client.admin().organization().auditLogs().list();
}
}
ruby: |-
require "openai"

openai = OpenAI::Client.new(admin_api_key: "My Admin API Key")

page = openai.admin.organization.audit_logs.list

puts(page)
response: |
{
"object": "list",
Expand Down Expand Up @@ -14788,11 +14846,19 @@ paths:
type: array
items:
type: string
- name: api_key_ids
in: query
description: Return only costs for these API keys.
required: false
schema:
type: array
items:
type: string
- name: group_by
in: query
description: >-
Group the costs by the specified fields. Support fields include
`project_id`, `line_item` and any combination of them.
`project_id`, `line_item`, `api_key_id` and any combination of them.
required: false
schema:
type: array
Expand All @@ -14801,6 +14867,7 @@ paths:
enum:
- project_id
- line_item
- api_key_id
- name: limit
in: query
description: >
Expand Down Expand Up @@ -14853,7 +14920,8 @@ paths:
"currency": "usd"
},
"line_item": null,
"project_id": null
"project_id": null,
"api_key_id": null
}
]
}
Expand Down Expand Up @@ -36840,6 +36908,13 @@ components:
When `group_by=project_id`, this field provides the project ID
of the grouped costs result.
- type: 'null'
api_key_id:
anyOf:
- type: string
description: >-
When `group_by=api_key_id`, this field provides the API Key ID
of the grouped costs result.
- type: 'null'
required:
- object
x-oaiMeta:
Expand Down
Loading