async_openai/types/containers/
container.rs

1use derive_builder::Builder;
2use serde::{Deserialize, Serialize};
3
4use crate::error::OpenAIError;
5
6use crate::types::InputSource;
7
8#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
9pub struct ContainerResource {
10    /// Unique identifier for the container.
11    pub id: String,
12    /// The type of this object.
13    pub object: String,
14    /// Name of the container.
15    pub name: String,
16    /// Unix timestamp (in seconds) when the container was created.
17    pub created_at: u64,
18    /// Status of the container (e.g., active, deleted).
19    pub status: String,
20    /// The container will expire after this time period. The anchor is the reference point for the expiration.
21    /// The minutes is the number of minutes after the anchor before the container expires.
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub expires_after: Option<ContainerExpiresAfter>,
24    /// Unix timestamp (in seconds) when the container was last active.
25    #[serde(skip_serializing_if = "Option::is_none")]
26    pub last_active_at: Option<u64>,
27}
28
29/// Expiration policy for containers.
30#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
31pub struct ContainerExpiresAfter {
32    /// Time anchor for the expiration time. Currently only 'last_active_at' is supported.
33    pub anchor: ContainerExpiresAfterAnchor,
34    pub minutes: u32,
35}
36
37/// Anchor for container expiration.
38#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
39#[serde(rename_all = "snake_case")]
40pub enum ContainerExpiresAfterAnchor {
41    LastActiveAt,
42}
43
44/// Request to create a container.
45/// openapi spec type: CreateContainerBody
46#[derive(Debug, Default, Clone, Builder, PartialEq, Serialize)]
47#[builder(name = "CreateContainerRequestArgs")]
48#[builder(pattern = "mutable")]
49#[builder(setter(into, strip_option), default)]
50#[builder(derive(Debug))]
51#[builder(build_fn(error = "OpenAIError"))]
52pub struct CreateContainerRequest {
53    /// Name of the container to create.
54    pub name: String,
55    /// IDs of files to copy to the container.
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub file_ids: Option<Vec<String>>,
58    /// Container expiration time in minutes relative to the 'anchor' time.
59    #[serde(skip_serializing_if = "Option::is_none")]
60    pub expires_after: Option<ContainerExpiresAfter>,
61}
62
63/// Response when listing containers.
64#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
65pub struct ContainerListResource {
66    /// The type of object returned, must be 'list'.
67    pub object: String,
68    /// A list of containers.
69    pub data: Vec<ContainerResource>,
70    /// The ID of the first container in the list.
71    pub first_id: Option<String>,
72    /// The ID of the last container in the list.
73    pub last_id: Option<String>,
74    /// Whether there are more containers available.
75    pub has_more: bool,
76}
77
78/// Response when deleting a container.
79#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
80pub struct DeleteContainerResponse {
81    pub id: String,
82    pub object: String,
83    pub deleted: bool,
84}
85
86// Container File types
87
88/// The container file object represents a file in a container.
89#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
90pub struct ContainerFileResource {
91    /// Unique identifier for the file.
92    pub id: String,
93    /// The type of this object (`container.file`).
94    pub object: String,
95    /// The container this file belongs to.
96    pub container_id: String,
97    /// Unix timestamp (in seconds) when the file was created.
98    pub created_at: u64,
99    /// Size of the file in bytes.
100    pub bytes: u32,
101    /// Path of the file in the container.
102    pub path: String,
103    /// Source of the file (e.g., `user`, `assistant`).
104    pub source: String,
105}
106
107/// Request to create a container file.
108/// openapi spec type: CreateContainerFileBody
109#[derive(Debug, Default, Clone, PartialEq)]
110pub struct CreateContainerFileRequest {
111    /// The File object (not file name) to be uploaded.
112    pub file: Option<InputSource>,
113    /// Name of the file to create.
114    pub file_id: Option<String>,
115}
116
117/// Response when listing container files.
118#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)]
119pub struct ContainerFileListResource {
120    /// The type of object returned, must be 'list'.
121    pub object: String,
122    /// A list of container files.
123    pub data: Vec<ContainerFileResource>,
124    /// The ID of the first file in the list.
125    pub first_id: Option<String>,
126    /// The ID of the last file in the list.
127    pub last_id: Option<String>,
128    /// Whether there are more files available.
129    pub has_more: bool,
130}
131
132/// Response when deleting a container file.
133#[derive(Debug, Deserialize, Clone, PartialEq, Serialize)]
134pub struct DeleteContainerFileResponse {
135    pub id: String,
136    pub object: String,
137    pub deleted: bool,
138}