This document describes the provider-specific protocols for uploading media files (images, audio, video, documents) to AI service providers. Each provider implements its own upload flow, typically involving presigned URLs, cloud storage services (Azure Blob Storage, AWS S3, Alibaba OSS), and multi-step upload confirmation processes.
For information about media type detection and format validation, see Media Type System. For details on how uploaded media is stored locally and served, see Media Storage. For image processing and conversion, see Image Processing Pipeline.
Most providers follow a three-phase upload pattern:
Key Components:
ImagesCache: Global dict for caching uploaded files by MD5 hashSources: g4f/Provider/needs_auth/OpenaiChat.py96-232 g4f/Provider/Yupp.py51-466 g4f/Provider/Qwen.py40-262
OpenAI uses Azure Blob Storage with a three-step upload process.
The OpenaiChat.upload_files method g4f/Provider/needs_auth/OpenaiChat.py139-232 handles the complete upload flow:
use_case | Content Type | Purpose |
|---|---|---|
"multimodal" | image/* | Vision models, image analysis |
"my_files" | Other types | Document processing, file attachments |
Sources: g4f/Provider/needs_auth/OpenaiChat.py80-94 g4f/Provider/needs_auth/OpenaiChat.py139-232
Yupp uses a presigned URL system with attachment registration.
The Yupp.sync_prepare_files method g4f/Provider/Yupp.py388-457 runs in a thread executor:
The returned file info dict contains:
Yupp implements cache size management g4f/Provider/Yupp.py337-344:
Sources: g4f/Provider/Yupp.py51-54 g4f/Provider/Yupp.py337-344 g4f/Provider/Yupp.py388-466
Qwen uses Alibaba Cloud OSS (Object Storage Service) with STS (Security Token Service) and OSS4-HMAC-SHA256 signatures.
The get_oss_headers function g4f/Provider/Qwen.py43-86 implements OSS4-HMAC-SHA256:
Qwen classifies files into different types g4f/Provider/Qwen.py209-227:
file_type | file_class | show_type | _type |
|---|---|---|---|
image/* | "vision" | "image" | "image" |
video/* | "video" | "video" | "video" |
audio/* | "audio" | "audio" | "audio" |
| Other | "document" | "file" | "file" |
Sources: g4f/Provider/Qwen.py40-41 g4f/Provider/Qwen.py43-86 g4f/Provider/Qwen.py161-262
LMArena uses a simpler approach with direct OSS upload.
The LMArena provider appears to use OSS-based uploads similar to Qwen, with file uploads integrated into the message flow. The provider maintains an ImagesCache dict g4f/Provider/needs_auth/LMArena.py60 for caching uploaded files.
Sources: g4f/Provider/needs_auth/LMArena.py60
All providers implement MD5-based caching to avoid re-uploading identical files.
All providers use the same pattern g4f/Provider/needs_auth/OpenaiChat.py162-166:
| Provider | Cache Variable | Max Size | Eviction Policy |
|---|---|---|---|
| OpenaiChat | ImagesCache dict | No limit | None |
| Yupp | ImagesCache dict | 1000 entries | FIFO (oldest 100 removed) |
| Qwen | ImagesCache dict | No limit | None |
| LMArena | ImagesCache dict | No limit | None |
Providers expose image_cache class attribute:
Sources: g4f/Provider/needs_auth/OpenaiChat.py96 g4f/Provider/needs_auth/OpenaiChat.py162-169 g4f/Provider/Yupp.py51-54 g4f/Provider/Yupp.py337-344 g4f/Provider/Qwen.py40
Different providers use different HTTP clients for uploads.
Used by OpenaiChat g4f/requests/curl_cffi.py98-130:
Used by Qwen g4f/requests/aiohttp.py34-75:
Used by Yupp g4f/Provider/Yupp.py57-82:
Sources: g4f/requests/curl_cffi.py98-130 g4f/requests/aiohttp.py34-75 g4f/Provider/Yupp.py57-82
Different providers require different header sets for uploads.
| Header | OpenAI | Yupp | Qwen OSS |
|---|---|---|---|
Content-Type | ✓ | ✓ | ✓ |
Content-Length | - | ✓ | - |
x-ms-blob-type | ✓ (BlockBlob) | - | - |
x-ms-version | ✓ (2020-04-08) | - | - |
Origin | ✓ | - | - |
x-oss-content-sha256 | - | - | ✓ (UNSIGNED-PAYLOAD) |
x-oss-date | - | - | ✓ (ISO 8601) |
x-oss-security-token | - | - | ✓ (STS token) |
x-oss-user-agent | - | - | ✓ |
authorization | - | - | ✓ (OSS4-HMAC-SHA256) |
Sources: g4f/Provider/needs_auth/OpenaiChat.py80-94
Upload operations include various error handling strategies.
Qwen checks for rate limit errors g4f/Provider/Qwen.py194-195:
OpenaiChat includes a 1-second delay between steps g4f/Provider/needs_auth/OpenaiChat.py201:
All providers use raise_for_status checks:
Sources: g4f/Provider/needs_auth/OpenaiChat.py191 g4f/Provider/needs_auth/OpenaiChat.py201 g4f/Provider/needs_auth/OpenaiChat.py221 g4f/Provider/Qwen.py190 g4f/Provider/Qwen.py194-195 g4f/Provider/Qwen.py207
Uploaded files are integrated into provider-specific message formats.
Sources: g4f/Provider/needs_auth/OpenaiChat.py270-303 g4f/Provider/Qwen.py417-442
Refresh this wiki