metaai-sdk 2.2.1__tar.gz → 2.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- metaai_sdk-2.3.2/.env.example +22 -0
- metaai_sdk-2.3.2/ChatGPT Image Jan 14, 2026, 06_59_02 PM.png +0 -0
- metaai_sdk-2.3.2/IMAGE_UPLOAD_README.md +547 -0
- metaai_sdk-2.3.2/IMPLEMENTATION_SUMMARY.md +175 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/LICENSE +28 -28
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/MANIFEST.in +48 -48
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/PKG-INFO +922 -927
- metaai_sdk-2.3.2/QUICK_USAGE.md +213 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/SECURITY.md +199 -199
- metaai_sdk-2.3.2/analyze_debug_responses.py +99 -0
- metaai_sdk-2.3.2/debug_async_video_test.py +164 -0
- metaai_sdk-2.3.2/download.jpg +0 -0
- metaai_sdk-2.3.2/enable_debug_logging.py +32 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/examples/complete_workflow_example.py +339 -339
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/examples/image_upload_example.py +248 -248
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/examples/image_workflow_complete.py +107 -107
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/examples/practical_use_cases.py +309 -309
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/examples/test_example.py +55 -55
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/examples/video_generation.py +130 -130
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/pyproject.toml +6 -3
- metaai_sdk-2.3.2/setup.cfg +4 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_api/api_server.py +360 -336
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_api/image_upload.py +173 -173
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_sdk.egg-info/PKG-INFO +922 -927
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_sdk.egg-info/SOURCES.txt +11 -3
- metaai_sdk-2.3.2/test_endpoints.py +396 -0
- metaai_sdk-2.3.2/test_image_upload.py +195 -0
- metaai_sdk-2.2.1/setup.cfg +0 -7
- metaai_sdk-2.2.1/setup.py +0 -56
- metaai_sdk-2.2.1/src/metaai_api/video_generation.py +0 -697
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/CHANGELOG.md +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/CONTRIBUTING.md +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/QUICK_REFERENCE.md +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/README.md +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/VIDEO_GENERATION_README.md +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/examples/simple_example.py +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/requirements.txt +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_api/__init__.py +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_api/client.py +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_api/exceptions.py +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_api/main.py +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_api/utils.py +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_sdk.egg-info/dependency_links.txt +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_sdk.egg-info/requires.txt +0 -0
- {metaai_sdk-2.2.1 → metaai_sdk-2.3.2}/src/metaai_sdk.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Meta AI API Cookie Configuration
|
|
2
|
+
# Copy this file to .env and fill in your Meta AI cookies
|
|
3
|
+
|
|
4
|
+
# Required cookies (Get these from your browser when logged into meta.ai)
|
|
5
|
+
META_AI_DATR=your_datr_cookie_value
|
|
6
|
+
META_AI_ABRA_SESS=your_abra_sess_cookie_value
|
|
7
|
+
META_AI_DPR=your_dpr_cookie_value
|
|
8
|
+
META_AI_WD=your_wd_cookie_value
|
|
9
|
+
|
|
10
|
+
# Optional cookies (recommended for better stability)
|
|
11
|
+
#META_AI_JS_DATR=your_js_datr_value
|
|
12
|
+
#META_AI_ABRA_CSRF=your_abra_csrf_value
|
|
13
|
+
|
|
14
|
+
# Refresh interval in seconds (default: 3600 = 1 hour)
|
|
15
|
+
META_AI_REFRESH_INTERVAL_SECONDS=3600
|
|
16
|
+
|
|
17
|
+
# How to get cookies:
|
|
18
|
+
# 1. Open browser and go to https://meta.ai
|
|
19
|
+
# 2. Open Developer Tools (F12)
|
|
20
|
+
# 3. Go to Application/Storage > Cookies > https://meta.ai
|
|
21
|
+
# 4. Copy the values for: datr, abra_sess, dpr, wd
|
|
22
|
+
# 5. Paste them above (without quotes)
|
|
Binary file
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
# Image Upload Feature Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The Meta AI API now supports **uploading images** for use in:
|
|
6
|
+
|
|
7
|
+
- 💬 **Chat/Image Analysis** - Analyze and describe uploaded images
|
|
8
|
+
- 🎨 **Similar Image Generation** - Create variations of uploaded images
|
|
9
|
+
- 🎬 **Video Generation** - Animate uploaded images with AI-generated videos
|
|
10
|
+
|
|
11
|
+
This feature uses Meta's rupload protocol with automatic `media_id` management and `attachment_metadata` (file size + MIME type) for all operations.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
✅ Upload images to Meta AI
|
|
16
|
+
✅ Support for JPEG, PNG, GIF, and other image formats
|
|
17
|
+
✅ **Chat**: Analyze and describe images
|
|
18
|
+
✅ **Image Generation**: Create similar images in different styles
|
|
19
|
+
✅ **Video Generation**: Animate static images
|
|
20
|
+
✅ Automatic MIME type detection and file size tracking
|
|
21
|
+
✅ UUID-based upload session management
|
|
22
|
+
✅ SDK and API server support
|
|
23
|
+
✅ Comprehensive error handling
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
The image upload functionality is included in the main package:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install metaai-api
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or install from source:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
git clone https://github.com/mir-ashiq/metaai-api.git
|
|
37
|
+
cd metaai-api
|
|
38
|
+
pip install -e .
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start
|
|
42
|
+
|
|
43
|
+
### SDK Usage - Complete Workflow
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from metaai_api import MetaAI
|
|
47
|
+
|
|
48
|
+
# Initialize with your cookies
|
|
49
|
+
ai = MetaAI(cookies={
|
|
50
|
+
"datr": "your_datr_cookie",
|
|
51
|
+
"abra_sess": "your_abra_sess_cookie",
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
# Step 1: Upload an image
|
|
55
|
+
result = ai.upload_image("path/to/image.jpg")
|
|
56
|
+
|
|
57
|
+
if result["success"]:
|
|
58
|
+
media_id = result["media_id"]
|
|
59
|
+
file_size = result["file_size"]
|
|
60
|
+
mime_type = result["mime_type"]
|
|
61
|
+
print(f"✓ Uploaded: {media_id}")
|
|
62
|
+
|
|
63
|
+
# Step 2: Analyze the image (Chat)
|
|
64
|
+
response = ai.prompt(
|
|
65
|
+
message="What do you see in this image? Describe it in detail.",
|
|
66
|
+
media_ids=[media_id],
|
|
67
|
+
attachment_metadata={'file_size': file_size, 'mime_type': mime_type}
|
|
68
|
+
)
|
|
69
|
+
print(f"Analysis: {response['message']}")
|
|
70
|
+
|
|
71
|
+
# Step 3: Generate similar images
|
|
72
|
+
response = ai.prompt(
|
|
73
|
+
message="Create a similar image in watercolor painting style",
|
|
74
|
+
media_ids=[media_id],
|
|
75
|
+
attachment_metadata={'file_size': file_size, 'mime_type': mime_type},
|
|
76
|
+
is_image_generation=True
|
|
77
|
+
)
|
|
78
|
+
for i, media in enumerate(response['media'], 1):
|
|
79
|
+
print(f"Generated Image {i}: {media['url']}")
|
|
80
|
+
|
|
81
|
+
# Step 4: Generate video from image
|
|
82
|
+
video_result = ai.generate_video(
|
|
83
|
+
prompt="generate a video with zoom in effect on this image",
|
|
84
|
+
media_ids=[media_id],
|
|
85
|
+
attachment_metadata={'file_size': file_size, 'mime_type': mime_type}
|
|
86
|
+
)
|
|
87
|
+
if video_result["success"]:
|
|
88
|
+
print(f"Video: {video_result['video_urls'][0]}")
|
|
89
|
+
else:
|
|
90
|
+
print(f"Error: {result['error']}")
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
````
|
|
94
|
+
|
|
95
|
+
### API Server Usage
|
|
96
|
+
|
|
97
|
+
1. **Set up environment variables** (`.env` file):
|
|
98
|
+
|
|
99
|
+
```env
|
|
100
|
+
META_AI_DATR=your_datr_cookie
|
|
101
|
+
META_AI_ABRA_SESS=your_abra_sess_cookie
|
|
102
|
+
META_AI_DPR=1.25
|
|
103
|
+
META_AI_WD=1528x732
|
|
104
|
+
````
|
|
105
|
+
|
|
106
|
+
2. **Start the server**:
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
python -m uvicorn metaai_api.api_server:app --host 0.0.0.0 --port 8000
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
3. **Complete API Workflow**:
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
# Step 1: Upload Image
|
|
116
|
+
curl -X POST "http://localhost:8000/upload" \
|
|
117
|
+
-F "file=@/path/to/image.jpg"
|
|
118
|
+
# Response: {"success": true, "media_id": "1453149056374564", "file_size": 3310, "mime_type": "image/jpeg", ...}
|
|
119
|
+
|
|
120
|
+
# Step 2: Analyze Image (Chat)
|
|
121
|
+
curl -X POST "http://localhost:8000/chat" \
|
|
122
|
+
-H "Content-Type: application/json" \
|
|
123
|
+
-d '{
|
|
124
|
+
"message": "What do you see in this image?",
|
|
125
|
+
"media_ids": ["1453149056374564"],
|
|
126
|
+
"attachment_metadata": {"file_size": 3310, "mime_type": "image/jpeg"}
|
|
127
|
+
}'
|
|
128
|
+
# Response: {"message": "The image captures a serene lake scene...", "sources": [], "media": []}
|
|
129
|
+
|
|
130
|
+
# Step 3: Generate Similar Images
|
|
131
|
+
curl -X POST "http://localhost:8000/image" \
|
|
132
|
+
-H "Content-Type: application/json" \
|
|
133
|
+
-d '{
|
|
134
|
+
"prompt": "Create a similar image in watercolor painting style",
|
|
135
|
+
"media_ids": ["1453149056374564"],
|
|
136
|
+
"attachment_metadata": {"file_size": 3310, "mime_type": "image/jpeg"}
|
|
137
|
+
}'
|
|
138
|
+
# Response: {"message": "", "sources": [], "media": [{"url": "https://...", "type": "IMAGE"}, ...]}
|
|
139
|
+
|
|
140
|
+
# Step 4: Generate Video from Image
|
|
141
|
+
curl -X POST "http://localhost:8000/video" \
|
|
142
|
+
-H "Content-Type: application/json" \
|
|
143
|
+
-d '{
|
|
144
|
+
"prompt": "generate a video with zoom in effect on this image",
|
|
145
|
+
"media_ids": ["1453149056374564"],
|
|
146
|
+
"attachment_metadata": {"file_size": 3310, "mime_type": "image/jpeg"}
|
|
147
|
+
}'
|
|
148
|
+
# Response: {"success": true, "video_urls": ["https://..."], ...}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
4. **Python API Client Example**:
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
import requests
|
|
155
|
+
|
|
156
|
+
# Upload
|
|
157
|
+
with open("image.jpg", "rb") as f:
|
|
158
|
+
upload_resp = requests.post("http://localhost:8000/upload", files={"file": f})
|
|
159
|
+
upload_data = upload_resp.json()
|
|
160
|
+
media_id = upload_data["media_id"]
|
|
161
|
+
metadata = {
|
|
162
|
+
"file_size": upload_data["file_size"],
|
|
163
|
+
"mime_type": upload_data["mime_type"]
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
# Chat
|
|
167
|
+
chat_resp = requests.post("http://localhost:8000/chat", json={
|
|
168
|
+
"message": "What's in this image?",
|
|
169
|
+
"media_ids": [media_id],
|
|
170
|
+
"attachment_metadata": metadata
|
|
171
|
+
})
|
|
172
|
+
print(chat_resp.json()["message"])
|
|
173
|
+
|
|
174
|
+
# Generate Images
|
|
175
|
+
image_resp = requests.post("http://localhost:8000/image", json={
|
|
176
|
+
"prompt": "Create similar in anime style",
|
|
177
|
+
"media_ids": [media_id],
|
|
178
|
+
"attachment_metadata": metadata
|
|
179
|
+
})
|
|
180
|
+
for media in image_resp.json()["media"]:
|
|
181
|
+
print(media["url"])
|
|
182
|
+
|
|
183
|
+
# Generate Video
|
|
184
|
+
video_resp = requests.post("http://localhost:8000/video", json={
|
|
185
|
+
"prompt": "animate this image with cinematic motion",
|
|
186
|
+
"media_ids": [media_id],
|
|
187
|
+
"attachment_metadata": metadata
|
|
188
|
+
})
|
|
189
|
+
print(video_resp.json()["video_urls"][0])
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
````
|
|
193
|
+
|
|
194
|
+
## API Reference
|
|
195
|
+
|
|
196
|
+
### `MetaAI.upload_image(file_path: str) -> Dict`
|
|
197
|
+
|
|
198
|
+
Upload an image file to Meta AI.
|
|
199
|
+
|
|
200
|
+
**Parameters:**
|
|
201
|
+
|
|
202
|
+
- `file_path` (str): Path to the local image file
|
|
203
|
+
|
|
204
|
+
**Returns:**
|
|
205
|
+
|
|
206
|
+
- `Dict` containing:
|
|
207
|
+
- `success` (bool): Whether the upload succeeded
|
|
208
|
+
- `media_id` (str): The uploaded image's media ID (if successful)
|
|
209
|
+
- `upload_session_id` (str): Unique upload session ID
|
|
210
|
+
- `file_name` (str): Original filename
|
|
211
|
+
- `file_size` (int): File size in bytes (required for prompts)
|
|
212
|
+
- `mime_type` (str): MIME type of the image (required for prompts)
|
|
213
|
+
- `error` (str): Error message (if failed)
|
|
214
|
+
|
|
215
|
+
**Example:**
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
result = ai.upload_image("photo.jpg")
|
|
219
|
+
|
|
220
|
+
if result["success"]:
|
|
221
|
+
media_id = result["media_id"]
|
|
222
|
+
file_size = result["file_size"]
|
|
223
|
+
mime_type = result["mime_type"]
|
|
224
|
+
|
|
225
|
+
# Use in chat/analysis
|
|
226
|
+
response = ai.prompt(
|
|
227
|
+
message="Describe this image",
|
|
228
|
+
media_ids=[media_id],
|
|
229
|
+
attachment_metadata={'file_size': file_size, 'mime_type': mime_type}
|
|
230
|
+
)
|
|
231
|
+
print(response["message"])
|
|
232
|
+
else:
|
|
233
|
+
print(f"Upload failed: {result['error']}")
|
|
234
|
+
````
|
|
235
|
+
|
|
236
|
+
### `MetaAI.prompt()` with Images
|
|
237
|
+
|
|
238
|
+
Use uploaded images in prompts for chat, analysis, or image generation.
|
|
239
|
+
|
|
240
|
+
**Parameters:**
|
|
241
|
+
|
|
242
|
+
- `message` (str): Your prompt/question
|
|
243
|
+
- `media_ids` (list): List of media IDs from uploaded images
|
|
244
|
+
- `attachment_metadata` (dict): **Required** - `{'file_size': int, 'mime_type': str}`
|
|
245
|
+
- `is_image_generation` (bool): Set True for image generation (optional)
|
|
246
|
+
|
|
247
|
+
**Example:**
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
# Chat/Analysis
|
|
251
|
+
response = ai.prompt(
|
|
252
|
+
message="What objects are in this image?",
|
|
253
|
+
media_ids=["1453149056374564"],
|
|
254
|
+
attachment_metadata={'file_size': 3310, 'mime_type': 'image/jpeg'}
|
|
255
|
+
)
|
|
256
|
+
print(response["message"]) # Text response
|
|
257
|
+
|
|
258
|
+
# Image Generation
|
|
259
|
+
response = ai.prompt(
|
|
260
|
+
message="Create similar in cyberpunk style",
|
|
261
|
+
media_ids=["1453149056374564"],
|
|
262
|
+
attachment_metadata={'file_size': 3310, 'mime_type': 'image/jpeg'},
|
|
263
|
+
is_image_generation=True
|
|
264
|
+
)
|
|
265
|
+
for img in response["media"]:
|
|
266
|
+
print(img["url"]) # 4 generated image URLs
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### `MetaAI.generate_video()` with Images
|
|
270
|
+
|
|
271
|
+
Generate videos from uploaded images.
|
|
272
|
+
|
|
273
|
+
**Parameters:**
|
|
274
|
+
|
|
275
|
+
- `prompt` (str): Video generation prompt
|
|
276
|
+
- `media_ids` (list): List of media IDs from uploaded images
|
|
277
|
+
- `attachment_metadata` (dict): **Required** - `{'file_size': int, 'mime_type': str}`
|
|
278
|
+
|
|
279
|
+
**Example:**
|
|
280
|
+
|
|
281
|
+
```python
|
|
282
|
+
result = ai.generate_video(
|
|
283
|
+
prompt="generate a video with zoom in effect",
|
|
284
|
+
media_ids=["1453149056374564"],
|
|
285
|
+
attachment_metadata={'file_size': 3310, 'mime_type': 'image/jpeg'}
|
|
286
|
+
)
|
|
287
|
+
if result["success"]:
|
|
288
|
+
print(result["video_urls"][0])
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Response Format
|
|
292
|
+
|
|
293
|
+
### Success Response
|
|
294
|
+
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"success": true,
|
|
298
|
+
"media_id": "1595995635158281",
|
|
299
|
+
"upload_session_id": "05c64ee5-1d97-43ba-9cae-0a5381644410",
|
|
300
|
+
"file_name": "photo.jpg",
|
|
301
|
+
"file_size": 3310,
|
|
302
|
+
"mime_type": "image/jpeg",
|
|
303
|
+
"response": {
|
|
304
|
+
"media_id": "1595995635158281"
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Error Response
|
|
310
|
+
|
|
311
|
+
```json
|
|
312
|
+
{
|
|
313
|
+
"success": false,
|
|
314
|
+
"error": "File not found at /path/to/image.jpg"
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Supported Image Formats
|
|
319
|
+
|
|
320
|
+
- JPEG (`.jpg`, `.jpeg`)
|
|
321
|
+
- PNG (`.png`)
|
|
322
|
+
- GIF (`.gif`)
|
|
323
|
+
- WEBP (`.webp`)
|
|
324
|
+
- Other formats supported by `mimetypes` module
|
|
325
|
+
|
|
326
|
+
## Error Handling
|
|
327
|
+
|
|
328
|
+
The upload method returns detailed error messages for various scenarios:
|
|
329
|
+
|
|
330
|
+
### File Not Found
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
result = ai.upload_image("nonexistent.jpg")
|
|
334
|
+
# Error: File not found at nonexistent.jpg
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Invalid File Type
|
|
338
|
+
|
|
339
|
+
```python
|
|
340
|
+
result = ai.upload_image("document.pdf")
|
|
341
|
+
# Error: Invalid file type: application/pdf. Only image files are supported.
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### Missing Tokens
|
|
345
|
+
|
|
346
|
+
```python
|
|
347
|
+
ai = MetaAI(cookies={"datr": "only_datr"})
|
|
348
|
+
result = ai.upload_image("image.jpg")
|
|
349
|
+
# Error: Missing required tokens (fb_dtsg, lsd). Please ensure cookies are properly set.
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Getting Cookies
|
|
353
|
+
|
|
354
|
+
To use the image upload feature, you need valid Meta AI cookies. Here's how to get them:
|
|
355
|
+
|
|
356
|
+
1. **Open your browser** (Chrome, Edge, Firefox)
|
|
357
|
+
2. **Navigate to** https://www.meta.ai/
|
|
358
|
+
3. **Log in** if required
|
|
359
|
+
4. **Open Developer Tools** (F12)
|
|
360
|
+
5. **Go to Application/Storage → Cookies**
|
|
361
|
+
6. **Copy the values** for:
|
|
362
|
+
- `datr`
|
|
363
|
+
- `abra_sess`
|
|
364
|
+
- `lsd` (optional, will auto-fetch)
|
|
365
|
+
- `fb_dtsg` (optional, will auto-fetch)
|
|
366
|
+
|
|
367
|
+
## Upload Process Flow
|
|
368
|
+
|
|
369
|
+
The image upload follows Meta's rupload protocol:
|
|
370
|
+
|
|
371
|
+
```
|
|
372
|
+
1. Generate UUID session ID
|
|
373
|
+
↓
|
|
374
|
+
2. Perform GET handshake (check if session exists)
|
|
375
|
+
↓
|
|
376
|
+
3. POST image data with headers:
|
|
377
|
+
- x-entity-length: file size
|
|
378
|
+
- x-entity-name: filename
|
|
379
|
+
- x-entity-type: MIME type
|
|
380
|
+
- desired_upload_handler: genai_document
|
|
381
|
+
↓
|
|
382
|
+
4. Receive media_id from server
|
|
383
|
+
↓
|
|
384
|
+
5. Use media_id in prompts/operations
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## Advanced Usage
|
|
388
|
+
|
|
389
|
+
### Custom Session Parameters
|
|
390
|
+
|
|
391
|
+
```python
|
|
392
|
+
from metaai_api.image_upload import ImageUploader
|
|
393
|
+
|
|
394
|
+
uploader = ImageUploader(session, cookies)
|
|
395
|
+
result = uploader.upload_image(
|
|
396
|
+
file_path="image.jpg",
|
|
397
|
+
fb_dtsg="your_fb_dtsg",
|
|
398
|
+
jazoest="your_jazoest",
|
|
399
|
+
lsd="your_lsd",
|
|
400
|
+
rev="1032041898", # Optional
|
|
401
|
+
s="custom_session", # Optional
|
|
402
|
+
hsi="custom_hsi" # Optional
|
|
403
|
+
)
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
### Batch Upload
|
|
407
|
+
|
|
408
|
+
```python
|
|
409
|
+
import os
|
|
410
|
+
from metaai_api import MetaAI
|
|
411
|
+
|
|
412
|
+
ai = MetaAI(cookies=your_cookies)
|
|
413
|
+
|
|
414
|
+
image_dir = "path/to/images"
|
|
415
|
+
media_ids = []
|
|
416
|
+
|
|
417
|
+
for filename in os.listdir(image_dir):
|
|
418
|
+
if filename.lower().endswith(('.jpg', '.jpeg', '.png')):
|
|
419
|
+
file_path = os.path.join(image_dir, filename)
|
|
420
|
+
result = ai.upload_image(file_path)
|
|
421
|
+
|
|
422
|
+
if result["success"]:
|
|
423
|
+
media_ids.append({
|
|
424
|
+
"filename": filename,
|
|
425
|
+
"media_id": result["media_id"]
|
|
426
|
+
})
|
|
427
|
+
print(f"✓ {filename}: {result['media_id']}")
|
|
428
|
+
else:
|
|
429
|
+
print(f"✗ {filename}: {result['error']}")
|
|
430
|
+
|
|
431
|
+
print(f"\nUploaded {len(media_ids)} images successfully")
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
## Future Enhancements
|
|
435
|
+
|
|
436
|
+
The following features are planned for future releases:
|
|
437
|
+
|
|
438
|
+
- [ ] Integration of `media_id` with `prompt()` method for image analysis
|
|
439
|
+
- [ ] Support for using uploaded images in similar image generation
|
|
440
|
+
- [ ] Support for using uploaded images in video generation
|
|
441
|
+
- [ ] Batch upload optimization
|
|
442
|
+
- [ ] Upload progress callbacks
|
|
443
|
+
- [ ] Image preprocessing (resize, compression)
|
|
444
|
+
|
|
445
|
+
## Troubleshooting
|
|
446
|
+
|
|
447
|
+
### Upload Returns 400 Error
|
|
448
|
+
|
|
449
|
+
**Issue:** Server returns 400 Bad Request
|
|
450
|
+
|
|
451
|
+
**Solution:**
|
|
452
|
+
|
|
453
|
+
- Refresh your cookies (they may have expired)
|
|
454
|
+
- Ensure all required tokens are present
|
|
455
|
+
- Check that the image file is valid
|
|
456
|
+
|
|
457
|
+
### Upload Returns 401/403 Error
|
|
458
|
+
|
|
459
|
+
**Issue:** Authentication failure
|
|
460
|
+
|
|
461
|
+
**Solution:**
|
|
462
|
+
|
|
463
|
+
- Log in to meta.ai in your browser
|
|
464
|
+
- Get fresh cookies
|
|
465
|
+
- Ensure `abra_sess` cookie is valid
|
|
466
|
+
|
|
467
|
+
### "Missing required tokens" Error
|
|
468
|
+
|
|
469
|
+
**Issue:** `fb_dtsg` or `lsd` tokens are missing
|
|
470
|
+
|
|
471
|
+
**Solution:**
|
|
472
|
+
|
|
473
|
+
- The SDK will auto-fetch these tokens if you provide `datr` and `abra_sess`
|
|
474
|
+
- Manually add them to your cookies dict if auto-fetch fails
|
|
475
|
+
|
|
476
|
+
### Large File Upload Fails
|
|
477
|
+
|
|
478
|
+
**Issue:** Upload times out or fails for large images
|
|
479
|
+
|
|
480
|
+
**Solution:**
|
|
481
|
+
|
|
482
|
+
- Resize images before upload (recommended max: 10MB)
|
|
483
|
+
- Use compression tools to reduce file size
|
|
484
|
+
- Check your network connection
|
|
485
|
+
|
|
486
|
+
## Examples
|
|
487
|
+
|
|
488
|
+
See the following files for complete examples:
|
|
489
|
+
|
|
490
|
+
- `examples/image_upload_example.py` - Comprehensive examples
|
|
491
|
+
- `test_image_upload.py` - Simple test script
|
|
492
|
+
|
|
493
|
+
## API Endpoints
|
|
494
|
+
|
|
495
|
+
### POST `/upload`
|
|
496
|
+
|
|
497
|
+
Upload an image file.
|
|
498
|
+
|
|
499
|
+
**Request:**
|
|
500
|
+
|
|
501
|
+
- Method: `POST`
|
|
502
|
+
- Content-Type: `multipart/form-data`
|
|
503
|
+
- Body: `file` (image file)
|
|
504
|
+
|
|
505
|
+
**Response:**
|
|
506
|
+
|
|
507
|
+
```json
|
|
508
|
+
{
|
|
509
|
+
"success": true,
|
|
510
|
+
"media_id": "1595995635158281",
|
|
511
|
+
"upload_session_id": "05c64ee5-1d97-43ba-9cae-0a5381644410",
|
|
512
|
+
"file_name": "image.jpg",
|
|
513
|
+
"file_size": 3310,
|
|
514
|
+
"mime_type": "image/jpeg"
|
|
515
|
+
}
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
## Security Considerations
|
|
519
|
+
|
|
520
|
+
⚠️ **Important Security Notes:**
|
|
521
|
+
|
|
522
|
+
1. **Never commit cookies to version control**
|
|
523
|
+
2. **Store cookies in environment variables or secure vaults**
|
|
524
|
+
3. **Refresh cookies periodically** (they expire)
|
|
525
|
+
4. **Use HTTPS** when deploying API server
|
|
526
|
+
5. **Implement rate limiting** for production deployments
|
|
527
|
+
6. **Validate file sizes** to prevent abuse
|
|
528
|
+
|
|
529
|
+
## License
|
|
530
|
+
|
|
531
|
+
This feature is part of the Meta AI API package and is licensed under the MIT License.
|
|
532
|
+
|
|
533
|
+
## Support
|
|
534
|
+
|
|
535
|
+
For issues, questions, or contributions:
|
|
536
|
+
|
|
537
|
+
- GitHub Issues: https://github.com/mir-ashiq/metaai-api/issues
|
|
538
|
+
- Documentation: See README.md and other documentation files
|
|
539
|
+
|
|
540
|
+
## Changelog
|
|
541
|
+
|
|
542
|
+
### Version 2.0.0+
|
|
543
|
+
|
|
544
|
+
- ✨ Added image upload functionality
|
|
545
|
+
- ✨ Added `ImageUploader` class
|
|
546
|
+
- ✨ Added `/upload` API endpoint
|
|
547
|
+
- ✨ Added comprehensive examples and documentation
|