Ignora e passa al contenuto principale

Questo browser non è più supportato.

Esegui l'aggiornamento a Microsoft Edge per sfruttare i vantaggi di funzionalità più recenti, aggiornamenti della sicurezza e supporto tecnico.

Scarica Microsoft Edge Scopri di più su Internet Explorer e Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Files

Create a file

POST /openai/v1/files

Creates a file from the supplied request.

Corpo della richiesta

The multipart request body.

Content-Type: multipart/form-data
file OpenAI.CreateFileRequest necessario

The File object (not file name) to be uploaded.

purpose OpenAI.CreateFileRequest necessario

The intended purpose of the uploaded file. One of: - assistants: Used in the Assistants API - batch: Used in the Batch API - fine-tune: Used for fine-tuning - vision: Images used for vision fine-tuning - user_data: Flexible file type for any purpose - evals: Used for eval data sets

expires_after OpenAI.FileExpirationAfter

The expiration policy for a file. By default, files with purpose=batch expire after 30 days and all other files are persisted until they are manually deleted.

anchor enum necessario

Anchor timestamp after which the expiration policy applies. Supported anchors: created_at.

created_at
seconds integer necessario

The number of seconds after the anchor time that the file will expire. Must be between 3600 (1 hour) and 2592000 (30 days).

Risposte

The request has succeeded.

Corpo

Content-Type: application/json
id string necessario

The file identifier, which can be referenced in the API endpoints.

bytes integer | null necessario

The size of the file, in bytes. In a completed file upload response, this can be null when the file size is not yet available.

created_at integer necessario

The Unix timestamp (in seconds) for when the file was created.

expires_at integer

The Unix timestamp (in seconds) for when the file will expire. In a completed file upload response, this can be null when no expiry is set.

filename string necessario

The name of the file.

object enum necessario

The object type, which is always file.

file
purpose enum necessario

The intended purpose of the file. Supported values are assistants, assistants_output, batch, batch_output, fine-tune, fine-tune-results, vision, and user_data.

assistantsassistants_outputbatchbatch_outputfine-tunefine-tune-resultsvisionuser_data
status enum necessario

Deprecated. The current status of the file, which can be either uploaded, processed, or error.

uploadedprocessederror
status_details string

Deprecated. For details on why a fine-tuning training file failed validation, see the error field on fine_tuning.job. Completed file upload responses can return null when these details are unset.

Client error

Corpo

Content-Type: application/json
error OpenAI.Error necessario
code string | null necessario
message string necessario
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Uno qualsiasi dei seguenti:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string necessario

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Corpo

Content-Type: application/json
error OpenAI.Error necessario
code string | null necessario
message string necessario
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Uno qualsiasi dei seguenti:
string
enum
potentially_unintended_data_transferpotentially_unintended_data_accesspotentially_unintended_destructive_activityother
detailed_explanation string

The public explanation for this block.

steer OpenAI._MisalignmentSteer
message string necessario

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Richiedi

curl https://api.openai.com/v1/files \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -F purpose="fine-tune" \
  -F file="@mydata.jsonl"
  -F expires_after[anchor]="created_at"
  -F expires_after[seconds]=2592000
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
file_object = client.files.create(
    file=b"Example data",
    purpose="assistants",
)
print(file_object.id)
import fs from "fs";
import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const file = await openai.files.create({
    file: fs.createReadStream("mydata.jsonl"),
    purpose: "fine-tune",
    expires_after: {
      anchor: "created_at",
      seconds: 2592000
    }
  });

  console.log(file);
}

main();
import fs from 'fs';
import OpenAI from 'openai';

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

const fileObject = await client.files.create({
  file: fs.createReadStream('fine-tune.jsonl'),
  purpose: 'assistants',
});

console.log(fileObject.id);
package main

import (
    "bytes"
    "context"
    "fmt"
    "io"

    "github.com/openai/openai-go"
    "github.com/openai/openai-go/option"
)

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    fileObject, err := client.Files.New(context.TODO(), openai.FileNewParams{
        File:    io.Reader(bytes.NewBuffer([]byte("Example data"))),
        Purpose: openai.FilePurposeAssistants,
    })
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", fileObject.ID)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.files.FileCreateParams;
import com.openai.models.files.FileObject;
import com.openai.models.files.FilePurpose;
import java.io.ByteArrayInputStream;

public final class Main {
    private Main() {}

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

        FileCreateParams params = FileCreateParams.builder()
            .file(new ByteArrayInputStream("Example data".getBytes()))
            .purpose(FilePurpose.ASSISTANTS)
            .build();
        FileObject fileObject = client.files().create(params);
    }
}
require "openai"

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

file_object = openai.files.create(file: StringIO.new("Example data"), purpose: :assistants)

puts(file_object)

Response

{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1677614202,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune",
}
it-it
Scelte sulla privacy
  • Dichiarazione di non responsabilità relativa all'intelligenza artificiale
  • Versioni precedenti
  • Blog
  • Collabora
  • Riservatezza
  • Privacy dei dati sanitari dei consumatori
  • Condizioni per l'utilizzo
  • Accessibilità
  • Marchi
  • © Microsoft 2026