A clean, public-ready FastAPI service for generating images and videos with Meta AI using a real browser session.
This project was built by reverse-engineering the browser flow used by https://meta.ai/create:
POST /api/graphqlusing Server-Sent Events (SSE)- collect
conversationId - fetch
GET /prompt/<conversationId>?_rsc=... - extract final image/video asset URLs
Important: this repository does not contain any personal cookies, tokens, or session data. You must supply your own browser session cookies locally.
GET /healthzPOST /image→ generate image URLsPOST /video→ generate video URLs (.mp4when available)POST /download→ download one asset to local storagePOST /download/batch→ download many assets to local storagePOST /image/download→ generate images and save them locally in one callPOST /video/download→ generate videos and save them locally in one callPOST /image-to-video→ generate a video from an existing image/media entityPOST /image-to-video/download→ generate a video from an image and save it locally in one call- Docker support
- clean
.env.examplefor self-setup
metaai-bridge-public/
├── app/
│ └── main.py
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── .env.example
├── .gitignore
├── LICENSE
└── README.md
- Python 3.11+ (if running locally without Docker)
- Or Docker + Docker Compose
- A working browser session logged into
https://meta.ai
This project does not use an official Meta API key. It uses the same authenticated browser session approach as the Meta AI web app.
At minimum, Meta AI currently needs a valid session containing cookies such as:
datrecto_1_sess
Other cookies/values often help stability:
wddprrd_challenge
The easiest way is to provide a single raw cookie string in .env.
- Open
https://meta.aiin your browser and sign in. - Press
F12to open DevTools. - Go to Application → Cookies →
https://meta.ai - Copy the cookie values you need.
- Create a local
.envfile from.env.example - Paste your values there.
Use one raw cookie string:
META_COOKIE_STRING=datr=...; ecto_1_sess=...; wd=1256x919; dpr=1; rd_challenge=...- Never commit your
.env - Never share your real cookies publicly
- Rotate / refresh cookies if Meta AI stops responding
Copy:
cp .env.example .envThen edit .env.
META_COOKIE_STRING=datr=...; ecto_1_sess=...; wd=1256x919; dpr=1; rd_challenge=...
META_AI_DATR=
META_AI_ECTO_1_SESS=
META_AI_WD=1256x919
META_AI_DPR=1
META_AI_RD_CHALLENGE=
TZ=Asia/Bangkok
META_DOWNLOAD_DIR=/app/downloads
META_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
META_ACCEPT_LANGUAGE=vi-VN,vi;q=0.9,fr-FR;q=0.8,fr;q=0.7,en-US;q=0.6,en;q=0.5docker compose up -d --buildcurl http://127.0.0.1:18081/healthzExpected:
{
"status": "ok",
"cookies": "ready",
"download_dir": "/app/downloads"
}Docker maps downloads here:
./downloads -> /app/downloads
So files will appear locally inside:
./downloads
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
uvicorn app.main:app --host 0.0.0.0 --port 8000Then call:
curl http://127.0.0.1:8000/healthzcurl http://127.0.0.1:18081/healthzMeta image generation currently supports 3 orientations:
VERTICALLANDSCAPESQUARE
{
"prompt": "1 dog sleep in a yard",
"orientation": "VERTICAL",
"timeout_seconds": 90
}curl -X POST http://127.0.0.1:18081/image \
-H 'Content-Type: application/json' \
-d '{
"prompt":"1 dog sleep in a yard",
"orientation":"VERTICAL",
"timeout_seconds":90
}'{
"success": true,
"conversation_id": "...",
"image_urls": [
"https://scontent-...jpeg",
"https://scontent-...jpeg"
],
"complete_seen": true,
"event_count": 12
}Video generation is slower than image generation.
This service will poll prompt state until .mp4 links appear or polling is exhausted.
{
"prompt": "blonde lady in the sun",
"timeout_seconds": 180,
"poll_attempts": 12,
"poll_interval_seconds": 5
}curl -X POST http://127.0.0.1:18081/video \
-H 'Content-Type: application/json' \
-d '{
"prompt":"blonde lady in the sun",
"timeout_seconds":180,
"poll_attempts":12,
"poll_interval_seconds":5
}'{
"success": true,
"conversation_id": "...",
"video_urls": [
"https://scontent-...mp4"
],
"complete_seen": true,
"event_count": 15,
"poll_attempts_used": 12,
"note": "Video flow auto-polls prompt state until mp4 links appear or attempts are exhausted."
}This endpoint uploads an image to Meta AI and returns a source_media_ent_id that can be used with POST /image-to-video.
Important:
- upload flow may require a valid
META_AI_ACCESS_TOKEN(ecto1:...) in addition to browser cookies - this token can expire and may need refreshing
Example using curl:
curl -X POST http://127.0.0.1:18081/upload \
-F "file=@./example.jpg"Typical response:
{
"success": true,
"source_media_ent_id": "123456789012345",
"upload_session_id": "...",
"file_name": "example.jpg",
"file_size": 100203,
"mime_type": "image/jpeg"
}{
"url": "https://example.com/file.jpg",
"filename": "optional-name.jpg",
"subdir": "tests"
}curl -X POST http://127.0.0.1:18081/download \
-H 'Content-Type: application/json' \
-d '{
"url":"https://example.com/file.jpg",
"subdir":"tests"
}'curl -X POST http://127.0.0.1:18081/download/batch \
-H 'Content-Type: application/json' \
-d '{
"urls":[
"https://example.com/a.jpg",
"https://example.com/b.jpg"
],
"subdir":"batch-1",
"prefix":"image"
}'curl -X POST http://127.0.0.1:18081/image/download \
-H 'Content-Type: application/json' \
-d '{
"prompt":"cyberpunk cat",
"orientation":"VERTICAL",
"timeout_seconds":90,
"subdir":"image-runs",
"filename_prefix":"cat"
}'This returns both:
- generation metadata
- local download results
curl -X POST http://127.0.0.1:18081/video/download \
-H 'Content-Type: application/json' \
-d '{
"prompt":"blonde lady in the sun",
"timeout_seconds":180,
"poll_attempts":12,
"poll_interval_seconds":5,
"subdir":"video-runs",
"filename_prefix":"clip"
}'curl -X POST http://127.0.0.1:18081/image-to-video \
-H 'Content-Type: application/json' \
-d '{
"source_media_ent_id":"913199711508625",
"source_media_url":"blob:https://meta.ai/ed8e0c9f-d9b3-4026-a911-7d4e7dd3a67f",
"prompt":"play guitar",
"timeout_seconds":180,
"poll_attempts":12,
"poll_interval_seconds":5
}'Notes:
source_media_ent_idis the key field.source_media_urlcan help, but Meta may still resolve via the entity id.conversation_id,entry_point,current_branch_path, andis_new_conversationcan be passed when reproducing a specific browser flow.
curl -X POST http://127.0.0.1:18081/image-to-video/download \
-H 'Content-Type: application/json' \
-d '{
"source_media_ent_id":"913199711508625",
"source_media_url":"blob:https://meta.ai/ed8e0c9f-d9b3-4026-a911-7d4e7dd3a67f",
"prompt":"play guitar",
"timeout_seconds":180,
"poll_attempts":12,
"poll_interval_seconds":5,
"subdir":"image-to-video-runs",
"filename_prefix":"clip"
}'Your .env is missing required session values.
Check:
META_COOKIE_STRING- or
META_AI_DATR - and
META_AI_ECTO_1_SESS
Try:
- increasing
timeout_seconds - increasing
poll_attempts - increasing
poll_interval_seconds - refreshing your Meta AI browser cookies
Suggested video-safe values:
{
"timeout_seconds": 180,
"poll_attempts": 12,
"poll_interval_seconds": 5
}This project depends on the current web flow used by Meta AI. If Meta changes request structure, headers, or render flow, the code may need to be updated.
This public repository intentionally excludes:
- real cookies
- real session values
- HAR files containing personal browsing data
- downloaded generated assets from private sessions
You are responsible for protecting your own session cookies.
MIT