from ai21 import AI21Client
# Initialize the client
client = AI21Client(
api_key="your_api_key_here" # or use environment variable AI21_API_KEY
)
# Delete a file by its ID
try:
client.library.files.delete("your-file-id-here")
print("File deleted successfully")
except Exception as e:
print(f"Error deleting file: {e}")
const axios = require('axios');
const apiKey = 'your_api_key_here';
const fileId = 'your-file-id-here';
axios.delete(`https://api.ai21.com/studio/v1/library/files/${fileId}`, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(() => console.log('File deleted successfully'))
.catch(error => console.error('Error deleting file:', error.message));
<?php
$apiKey = 'your_api_key_here';
$fileId = 'your-file-id-here';
$ch = curl_init("https://api.ai21.com/studio/v1/library/files/$fileId");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error deleting file: ' . curl_error($ch);
} else {
echo "File deleted successfully";
}
curl_close($ch);
?>
package main
import (
"fmt"
"net/http"
)
func main() {
apiKey := "your_api_key_here"
fileId := "your-file-id-here"
req, _ := http.NewRequest("DELETE", "https://api.ai21.com/studio/v1/library/files/"+fileId, nil)
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error deleting file:", err)
} else {
fmt.Println("File deleted successfully")
resp.Body.Close()
}
}
curl -X DELETE https://api.ai21.com/studio/v1/library/files/your-file-id-here \
-H "Authorization: Bearer your_api_key_here"
import okhttp3.*;
public class DeleteFile {
public static void main(String[] args) throws Exception {
String apiKey = "your_api_key_here";
String fileId = "your-file-id-here";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.ai21.com/studio/v1/library/files/" + fileId)
.delete()
.addHeader("Authorization", "Bearer " + apiKey)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
System.out.println("File deleted successfully");
} else {
System.out.println("Error deleting file: " + response.message());
}
}
}
}
File Library Management
Delete file
Delete the specified file from the library.
DELETE
/
studio
/
v1
/
library
/
files
/
{file_id}
from ai21 import AI21Client
# Initialize the client
client = AI21Client(
api_key="your_api_key_here" # or use environment variable AI21_API_KEY
)
# Delete a file by its ID
try:
client.library.files.delete("your-file-id-here")
print("File deleted successfully")
except Exception as e:
print(f"Error deleting file: {e}")
const axios = require('axios');
const apiKey = 'your_api_key_here';
const fileId = 'your-file-id-here';
axios.delete(`https://api.ai21.com/studio/v1/library/files/${fileId}`, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(() => console.log('File deleted successfully'))
.catch(error => console.error('Error deleting file:', error.message));
<?php
$apiKey = 'your_api_key_here';
$fileId = 'your-file-id-here';
$ch = curl_init("https://api.ai21.com/studio/v1/library/files/$fileId");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error deleting file: ' . curl_error($ch);
} else {
echo "File deleted successfully";
}
curl_close($ch);
?>
package main
import (
"fmt"
"net/http"
)
func main() {
apiKey := "your_api_key_here"
fileId := "your-file-id-here"
req, _ := http.NewRequest("DELETE", "https://api.ai21.com/studio/v1/library/files/"+fileId, nil)
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error deleting file:", err)
} else {
fmt.Println("File deleted successfully")
resp.Body.Close()
}
}
curl -X DELETE https://api.ai21.com/studio/v1/library/files/your-file-id-here \
-H "Authorization: Bearer your_api_key_here"
import okhttp3.*;
public class DeleteFile {
public static void main(String[] args) throws Exception {
String apiKey = "your_api_key_here";
String fileId = "your-file-id-here";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.ai21.com/studio/v1/library/files/" + fileId)
.delete()
.addHeader("Authorization", "Bearer " + apiKey)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
System.out.println("File deleted successfully");
} else {
System.out.println("Error deleting file: " + response.message());
}
}
}
}
Restrictions:
Files in
PROCESSING status cannot be deleted. Attempts to delete such files will result in a 422 error.
Responses
Response 200
Successful deletion. No body content.Response 422
File by this ID does not exist.from ai21 import AI21Client
# Initialize the client
client = AI21Client(
api_key="your_api_key_here" # or use environment variable AI21_API_KEY
)
# Delete a file by its ID
try:
client.library.files.delete("your-file-id-here")
print("File deleted successfully")
except Exception as e:
print(f"Error deleting file: {e}")
const axios = require('axios');
const apiKey = 'your_api_key_here';
const fileId = 'your-file-id-here';
axios.delete(`https://api.ai21.com/studio/v1/library/files/${fileId}`, {
headers: {
'Authorization': `Bearer ${apiKey}`
}
})
.then(() => console.log('File deleted successfully'))
.catch(error => console.error('Error deleting file:', error.message));
<?php
$apiKey = 'your_api_key_here';
$fileId = 'your-file-id-here';
$ch = curl_init("https://api.ai21.com/studio/v1/library/files/$fileId");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $apiKey"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error deleting file: ' . curl_error($ch);
} else {
echo "File deleted successfully";
}
curl_close($ch);
?>
package main
import (
"fmt"
"net/http"
)
func main() {
apiKey := "your_api_key_here"
fileId := "your-file-id-here"
req, _ := http.NewRequest("DELETE", "https://api.ai21.com/studio/v1/library/files/"+fileId, nil)
req.Header.Set("Authorization", "Bearer "+apiKey)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error deleting file:", err)
} else {
fmt.Println("File deleted successfully")
resp.Body.Close()
}
}
curl -X DELETE https://api.ai21.com/studio/v1/library/files/your-file-id-here \
-H "Authorization: Bearer your_api_key_here"
import okhttp3.*;
public class DeleteFile {
public static void main(String[] args) throws Exception {
String apiKey = "your_api_key_here";
String fileId = "your-file-id-here";
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url("https://api.ai21.com/studio/v1/library/files/" + fileId)
.delete()
.addHeader("Authorization", "Bearer " + apiKey)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
System.out.println("File deleted successfully");
} else {
System.out.println("Error deleting file: " + response.message());
}
}
}
}
Was this page helpful?
⌘I

