跳到主要內容

已不再支援此瀏覽器。

請升級至 Microsoft Edge,以利用最新功能、安全性更新和技術支援。

下載 Microsoft Edge Internet Explorer 和 Microsoft Edge 的詳細資訊
microsoft-foundry.rest.security.o-auth2-auth

Uploads

Create an upload

POST /openai/v1/uploads

Creates an upload from the supplied request.

要求本文

The request body.

Content-Type: application/json
filename string 必要

The name of the file to upload.

purpose enum 必要

The intended purpose of the uploaded file. See the documentation on File purposes.

assistantsbatchfine-tunevision
bytes integer 必要
mime_type string 必要

The MIME type of the file. This must fall within the supported MIME types for your file purpose. See the supported MIME types for assistants and vision.

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 必要

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

created_at
seconds integer 必要

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

回覆

The request has succeeded.

主體

Content-Type: application/json
id string 必要

The Upload unique identifier, which can be referenced in API endpoints.

created_at integer 必要

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

filename string 必要

The name of the file to be uploaded.

bytes integer 必要
purpose string 必要

The intended purpose of the file. Please refer here for acceptable values.

status enum 必要

The status of the Upload.

pendingcompletedcancelledexpired
expires_at integer 必要

The Unix timestamp (in seconds) for when the Upload will expire.

object enum

The object type, which is always "upload".

upload
file OpenAI.OpenAIFile | null

The ready File object after the Upload is completed.

id string 必要

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

bytes integer | null 必要

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 必要

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 必要

The name of the file.

object enum 必要

The object type, which is always file.

file
purpose enum 必要

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 必要

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

主體

Content-Type: application/json
error OpenAI.Error 必要
code string | null 必要
message string 必要
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
以下任何一項:
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 必要

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Server error

主體

Content-Type: application/json
error OpenAI.Error 必要
code string | null 必要
message string 必要
param string | null
type string
misalignment OpenAI.MisalignmentErrorDetailsResource
review_target string | null
error_type string | enum
以下任何一項:
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 必要

The public continuation instruction.

details OpenAI.Error[]
additionalInfo object
debugInfo object

Request

curl https://api.openai.com/v1/uploads \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "purpose": "fine-tune",
    "filename": "training_examples.jsonl",
    "bytes": 2147483648,
    "mime_type": "text/jsonl",
    "expires_after": {
      "anchor": "created_at",
      "seconds": 3600
    }
  }'
import OpenAI from 'openai';

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

const upload = await client.uploads.create({
  bytes: 0,
  filename: 'filename',
  mime_type: 'mime_type',
  purpose: 'assistants',
});

console.log(upload.id);
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ.get("OPENAI_API_KEY"),  # This is the default and can be omitted
)
upload = client.uploads.create(
    bytes=0,
    filename="filename",
    mime_type="mime_type",
    purpose="assistants",
)
print(upload.id)
package main

import (
    "context"
    "fmt"

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

func main() {
    client := openai.NewClient(
        option.WithAPIKey("My API Key"),
    )
    upload, err := client.Uploads.New(context.TODO(), openai.UploadNewParams{
        Bytes:    0,
        Filename: "filename",
        MimeType: "mime_type",
        Purpose:  openai.FilePurposeAssistants,
    })
    if err != nil {
        panic(err.Error())
    }
    fmt.Printf("%+v
", upload.ID)
}
package com.openai.example;

import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.files.FilePurpose;
import com.openai.models.uploads.Upload;
import com.openai.models.uploads.UploadCreateParams;

public final class Main {
    private Main() {}

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

        UploadCreateParams params = UploadCreateParams.builder()
            .bytes(0L)
            .filename("filename")
            .mimeType("mime_type")
            .purpose(FilePurpose.ASSISTANTS)
            .build();
        Upload upload = client.uploads().create(params);
    }
}
require "openai"

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

upload = openai.uploads.create(bytes: 0, filename: "filename", mime_type: "mime_type", purpose: :assistants)

puts(upload)

回應

{
  "id": "upload_abc123",
  "object": "upload",
  "bytes": 2147483648,
  "created_at": 1719184911,
  "filename": "training_examples.jsonl",
  "purpose": "fine-tune",
  "status": "pending",
  "expires_at": 1719127296
}
zh-tw
您的隱私權選擇
  • AI 免責聲明
  • 舊版本
  • 部落格
  • 參與
  • 隱私權
  • 消費者健康隱私
  • 使用規定
  • 商標
  • © Microsoft 2026