Zu Hauptinhalt wechseln

Dieser Browser wird nicht mehr unterstützt.

Führen Sie ein Upgrade auf Microsoft Edge durch, um die neuesten Features, Sicherheitsupdates und den technischen Support zu nutzen.

Microsoft Edge herunterladen Weitere Informationen zu Internet Explorer und Microsoft Edge
microsoft-foundry.rest.security.o-auth2-auth

Files

Create a file

POST /openai/v1/files

Creates a file from the supplied request.

Anforderungstext

The multipart request body.

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

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

purpose OpenAI.CreateFileRequest Erforderlich

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 Erforderlich

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

created_at
seconds integer Erforderlich

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

Antworten

The request has succeeded.

Text

Content-Type: application/json
id string Erforderlich

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

bytes integer | null Erforderlich

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 Erforderlich

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 Erforderlich

The name of the file.

object enum Erforderlich

The object type, which is always file.

file
purpose enum Erforderlich

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 Erforderlich

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

Text

Content-Type: application/json
error OpenAI.Error Erforderlich
code string | null Erforderlich
message string Erforderlich
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Eines der folgenden Elemente:
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 Erforderlich

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

Text

Content-Type: application/json
error OpenAI.Error Erforderlich
code string | null Erforderlich
message string Erforderlich
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
Eines der folgenden Elemente:
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 Erforderlich

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Anfordern

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)

Antwort

{
  "id": "file-abc123",
  "object": "file",
  "bytes": 120000,
  "created_at": 1677610602,
  "expires_at": 1677614202,
  "filename": "mydata.jsonl",
  "purpose": "fine-tune",
}
de-de
Ihre Datenschutzoptionen
  • KI-Haftungsausschluss
  • Frühere Versionen
  • Blog
  • Mitwirken
  • Datenschutz
  • Consumer Health Privacy
  • Nutzungsbedingungen
  • Impressum
  • Marken
  • © Microsoft 2026