Chat with Meta AI, analyze images, and generate content from Go.
ู ูุชุจุฉ Go ู ุณุชููุฉ ููุชุนุงู ู ู ุน Meta AI ุนุจุฑ HTTP ูGraphQL ูุจุฑูุชูููู Clippy ุงูุซูุงุฆู ุนูู WebSocket. ูุนุชู ุฏ ุชูููุฐ ุงูู ุญุงุฏุซุฉ ุนูู ุฅุทุงุฑุงุช ู ูุชูุทุฉ ู ู ุงูู ุชุตูุญ ูู ุซุจุชุฉ ุจุงุฎุชุจุงุฑุงุช golden ูุถู ุงู ุตุญุฉ ุงูุจููุฉ ูุงูู subtype.
| ุงูู ูุฒุฉ | ุงูุญุงูุฉ | ุงููุตู |
|---|---|---|
| ๐ฌ Chat | โ ูุนู ู | ู ุญุงุฏุซุฉ ูุตูุฉ ุนุจุฑ WebSocket (template mode) |
| ๐ก Streaming | โ ูุนู ู | ุจุซ ุงูุฑุฏูุฏ ุนุจุฑ Go channels |
| ๐ค ุฑูุน ุตูุฑ | โ ูุนู ู | ุฑูุน ูู rupload.meta.ai (ู ุน lowercase headers) |
| ๐ ุชุญููู ุตูุฑ | โ ูุนู ู | ุฑูุน + ุณุคุงู โ ุงูุฐูุงุก ุงูุงุตุทูุงุนู ูุฑู ุงูุตูุฑุฉ |
| ๐จ ุชูููุฏ ุตูุฑ | โ ูุนู ู | ูุต โ ุตูุฑุฉ ุนุจุฑ ุจุซ ุงูุดุงุช + ุงุณุชุทูุงุน mediaLibraryFeed |
| ๐ฌ ุชูููุฏ ููุฏูู | โ ูุนู ู | ูุต โ ููุฏูู ุนุจุฑ ุจุซ ุงูุดุงุช + ุงุณุชุทูุงุน mediaLibraryFeed |
| ๐ ุงูุณุฌู | โ ูุนู ู | ุงุณุชุฑุฌุงุน ุงูู ุญุงุฏุซุงุช ุงูุณุงุจูุฉ |
| ๐๏ธ ุงูู ูุงุถูุน | โ ูุนู ู | ุฅุฏุงุฑุฉ ู ุญุงุฏุซุงุช ู ุชุนุฏุฏุฉ |
go get github.com/smart-studio/metaai-go# ู
ุชุบูุฑุงุช ุงูุจูุฆุฉ
export META_AI_DATR=your_datr_cookie
export META_AI_ECTO_1_SESS=your_session_cookie
export META_AI_ACCESS_TOKEN=ecto1:your_oauth_token๐ ููููุฉ ุงูุญุตูู ุนูู ุงูู cookies
- ุณุฌู ุงูุฏุฎูู ุฅูู meta.ai
- ุงูุชุญ DevTools (F12) โ Application โ Cookies โ
https://meta.ai - ุงูุณุฎ ููู
datrูecto_1_sess - ููุญุตูู ุนูู ุงูุชูููุ ุงูุชุญ Console ูุงูุชุจ:
document.documentElement.outerHTML.match(/ecto1:[A-Za-z0-9_-]{20,}/)[0]package main
import (
"context"
"fmt"
"log"
"github.com/smart-studio/metaai-go"
)
func main() {
client, err := metaai.NewClient()
if err != nil { log.Fatal(err) }
ctx := context.Background()
// โโโ ๐ฌ Chat โโโ
reply, _ := client.Chat(ctx, "What is 2+2?", nil)
fmt.Println(reply) // "2 + 2 = 4"
// โโโ ๐ค ุฑูุน + ๐ ุชุญููู ุตูุฑุฉ โโโ
analysis, _ := client.AnalyzeImage(ctx, "photo.png", "", "What's in this image?", nil)
fmt.Println(analysis) // AI ุชุตู ุงูุตูุฑุฉ ุจุงูุชูุตูู
// โโโ ๐จ ุชูููุฏ ุตูุฑุฉ โโโ
img, _ := client.GenerateImage(ctx, "a sunset over mountains", "LANDSCAPE", 1)
fmt.Println(img.Status) // "READY"
// โโโ ๐ก ุจุซ ู
ุชุฏูู โโโ
for chunk := range client.StreamChat(ctx, "Write a poem about Go", nil) {
if chunk.Err != nil { break }
fmt.Print(chunk.Text) // ุทุจุงุนุฉ ูุญุธูุฉ
}
}๐ง ุฎูุงุฑุงุช ู ุชูุฏู ุฉ
// ุฎูุงุฑุงุช ุงูุนู
ูู
client, _ := metaai.NewClient(
metaai.WithCookies(map[string]string{"datr": "...", "ecto_1_sess": "..."}),
metaai.WithAccessToken("ecto1:..."),
metaai.WithProxy("http://proxy:8080"),
metaai.WithDefaultThinking(true),
metaai.WithDefaultMode("analyze"),
)
// ุฎูุงุฑุงุช ุงูู
ุญุงุฏุซุฉ
opts := &metaai.ChatOptions{
Topic: "coding", // ู
ุญุงุฏุซุฉ ูู ู
ูุถูุน ู
ุญุฏุฏ
NewConversation: true, // ู
ุญุงุฏุซุฉ ุฌุฏูุฏุฉ
Thinking: boolPtr(true), // ูุถุน ุงูุชูููุฑ
Mode: strPtr("analyze"),
}
// ุงูู
ูุงุถูุน
client.NewTopic("math", boolPtr(true), nil, nil)
client.SetTopic("math")
topics := client.ListTopics()
// ุงูุณุฌู
history, _ := client.GetConversationHistory(ctx, 20, 0)The cmd/metaai-server binary exposes the SDK as an HTTP server that speaks
both the OpenAI Chat Completions API and the Anthropic Messages API, so
agents like Claude Code (and any OpenAI-compatible tool) can use Meta AI as
a backend.
|
Drop-in for any OpenAI SDK / LangChain / Cursor |
Point Claude Code at it via |
| Endpoint | Method | Shape | Description | Status |
|---|---|---|---|---|
/ |
GET | โ | Service info + available models | โ Working |
/health |
GET | โ | Liveness probe ({"status":"ok"}) |
โ Working |
/v1/models |
GET | OpenAI | List virtual models (meta-ai, meta-ai-think, โฆ) |
โ Working |
/v1/chat/completions |
POST | OpenAI | Chat completion โ streaming (stream:true) supported |
โ Working |
/chat/completions |
POST | OpenAI | Alias (no /v1 prefix) for older clients |
โ Working |
/v1/messages |
POST | Anthropic | Messages API โ what Claude Code uses | โ Working |
/messages |
POST | Anthropic | Alias (no /v1 prefix) |
โ Working |
Authentication: optional bearer token via META_AI_PROXY_TOKEN. Clients
send it in Authorization: Bearer โฆ (OpenAI) or x-api-key: โฆ (Anthropic).
If unset, the proxy accepts any caller.
| Model name | Maps to | Example use |
|---|---|---|
meta-ai (default) |
normal chat | general Q&A, code, explanations |
meta-ai-think |
extended-thinking mode | complex reasoning, math, planning |
meta-ai-fast |
instant mode | quick replies |
meta-ai-analyze |
chat mode override | focused analysis |
meta-ai-learn |
chat mode override | learning/explainer mode |
meta-ai-image |
image generation | returns image URL(s) in the content |
meta-ai-video |
video generation | returns video URL(s) in the content |
Unknown model names map heuristically:
gpt-4o,gpt-3.5-turbo,claude-3-5-sonnet,claude-3-opus, etc. all work (falling back to default chat). Vision input (OpenAIimage_urland Anthropicimagecontent blocks) is uploaded and analyzed. Tool/function-calling fields are accepted but ignored (Meta AI has no native tool API).
# Set the SDK credentials (same ones the library uses)
export META_AI_DATR=...
export META_AI_ECTO_1_SESS=...
export META_AI_ACCESS_TOKEN=ecto1:...
# Optional: require a bearer token from clients
export META_AI_PROXY_TOKEN=change-me
go run ./cmd/metaai-server # default :8787
# or: make runexport ANTHROPIC_BASE_URL=http://localhost:8787
export ANTHROPIC_API_KEY=$META_AI_PROXY_TOKEN # must match the proxy token
# then launch Claude Code โ its /v1/messages calls are proxied to Meta AIcurl http://localhost:8787/v1/chat/completions \
-H "Authorization: Bearer $META_AI_PROXY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "meta-ai-think",
"messages": [{"role":"user","content":"Explain goroutines"}],
"stream": true
}'Response (OpenAI shape):
{
"id": "chatcmpl-7a3f9c1b2e4d",
"object": "chat.completion",
"created": 1781964000,
"model": "meta-ai-think",
"choices": [{
"index": 0,
"message": {"role": "assistant", "content": "Goroutines are lightweight threads..."},
"finish_reason": "stop"
}],
"usage": {"prompt_tokens": 4, "completion_tokens": 96, "total_tokens": 100}
}curl http://localhost:8787/v1/messages \
-H "x-api-key: $META_AI_PROXY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "meta-ai",
"max_tokens": 1024,
"stream": true,
"messages": [{"role":"user","content":"What is 2+2?"}]
}'Response (Anthropic shape, streamed):
event: message_start
data: {"type":"message_start","message":{"id":"msg_...","role":"assistant",...}}
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Two plus two equals four."}}
event: message_stop
data: {"type":"message_stop"}
Both APIs accept images in the latest user message. OpenAI uses image_url,
Anthropic uses image content blocks. They are downloaded (or decoded from
data: URLs) and run through AnalyzeImage:
curl http://localhost:8787/v1/chat/completions \
-H "Authorization: Bearer $META_AI_PROXY_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "meta-ai",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What colors are in this image?"},
{"type": "image_url", "image_url": {"url": "https://example.com/photo.jpg"}}
]
}]
}'Concurrency: the proxy serializes chat turns (the SDK reuses one WebSocket per conversation). Fine for agent-style sequential use; add a client pool if you need parallel turns. Each request is stateless and sends the full transcript to Meta AI, matching how OpenAI/Anthropic clients behave.
The cmd/metaai-rest binary exposes the SDK as a REST API server with the same
surface as the canonical SDK REST API โ a drop-in for any HTTP client.
| Endpoint | Method | Description | Status |
|---|---|---|---|
/ |
GET | Service info + available endpoints | โ Working |
/healthz |
GET | Health check ({"status":"ok"}) |
โ Working |
/chat |
POST | Send chat messages (streaming supported) | โ Working |
/upload |
POST | Upload images for generation/analysis | โ Working |
/image |
POST | Generate images from text | โ Working |
/video |
POST | Generate video (blocks until complete) | โ Working |
/video/extend |
POST | Extend a video from a media ID | โ Working |
/video/async |
POST | Start async video generation | โ Working |
/video/jobs/{job_id} |
GET | Poll an async video job's status | โ Working |
# Credentials (same ones the SDK uses)
export META_AI_DATR=...
export META_AI_ECTO_1_SESS=...
# Optional bearer token clients must send
export META_AI_REST_TOKEN=change-me
go run ./cmd/metaai-rest # default :8000
# or: make run-restChat:
curl http://localhost:8000/chat \
-H "Authorization: Bearer $META_AI_REST_TOKEN" \
-H "Content-Type: application/json" \
-d '{"message":"What is 2+2?"}'
# โ {"success":true,"message":"Two plus two equals four."}Generate image:
curl http://localhost:8000/image \
-H "Authorization: Bearer $META_AI_REST_TOKEN" \
-H "Content-Type: application/json" \
-d '{"prompt":"a red apple","orientation":"SQUARE"}'
# โ {"success":true,"prompt":"a red apple","image_urls":["https://scontent..."],"media_ids":["1102..."],"status":"READY"}Async video generation + polling:
# 1) Start the job
JOB=$(curl -s http://localhost:8000/video/async \
-H "Authorization: Bearer $META_AI_REST_TOKEN" \
-H "Content-Type: application/json" \
-d '{"prompt":"sunset over ocean"}' | jq -r .job_id)
# 2) Poll until "completed"
curl -s http://localhost:8000/video/jobs/$JOB \
-H "Authorization: Bearer $META_AI_REST_TOKEN"
# โ {"job_id":"...","status":"completed","result":{"success":true,"video_urls":[...]}}Upload an image (multipart):
curl http://localhost:8000/upload \
-H "Authorization: Bearer $META_AI_REST_TOKEN" \
-F "file=@photo.jpg"
# โ {"success":true,"media_id":"1575...","file_name":"photo.jpg","file_size":12345,"mime_type":"image/jpeg"}Authentication: optional bearer token via
META_AI_REST_TOKEN. Clients send it inAuthorization: Bearer โฆorx-api-key: โฆ. If unset, the server accepts any caller.
| ุงูุฏุงูุฉ | ุงููุตู | ุงูู ุซุงู |
|---|---|---|
Chat(ctx, msg, opts) |
ุฅุฑุณุงู ุฑุณุงูุฉ ูุงุณุชูุงู ุงูุฑุฏ | client.Chat(ctx, "Hello", nil) |
StreamChat(ctx, msg, opts) |
ุจุซ ุงูุฑุฏ ุนุจุฑ channel | range client.StreamChat(ctx, "Hi", nil) |
UploadImage(ctx, path) |
ุฑูุน ุตูุฑุฉ โ media_id | client.UploadImage(ctx, "photo.jpg") |
AnalyzeImage(ctx, path, mediaID, q, opts) |
ุฑูุน + ุชุญููู | client.AnalyzeImage(ctx, "p.png", "", "Describe", nil) |
GenerateImage(ctx, prompt, orient, num) |
ุชูููุฏ ุตูุฑุฉ | client.GenerateImage(ctx, "a cat", "SQUARE", 1) |
GenerateVideo(ctx, prompt) |
ุชูููุฏ ููุฏูู | client.GenerateVideo(ctx, "waves") |
GetConversationHistory(ctx, limit, offset) |
ุงูุณุฌู | client.GetConversationHistory(ctx, 10, 0) |
NewTopic / SetTopic / ListTopics |
ุฅุฏุงุฑุฉ ุงูู ูุงุถูุน | client.NewTopic("work", nil, nil, nil) |
go/
โโโ metaai.go # ุงูุนู
ูู (ููุทุฉ ุงูุฏุฎูู)
โโโ chat.go # ุงูู
ุญุงุฏุซุฉ (WebSocket template mode)
โโโ analyze.go # ุชุญููู ุงูุตูุฑ (ุญูู attachment)
โโโ generation_client.go # ุชูููุฏ ุงูุตูุฑ/ุงูููุฏูู
โโโ session.go # ุฅุฏุงุฑุฉ ุงูู
ูุงุถูุน
โโโ graphql.go # GraphQL HTTP
โโโ internal/
โ โโโ clippy/ # ุงูุจุฑูุชูููู ุงูุซูุงุฆู (encoder + parser + template)
โ โ โโโ proto.go # protobuf primitives
โ โ โโโ frame.go # ุจูุงุก ุงูุฅุทุงุฑ
โ โ โโโ parse.go # ุชุญููู ุงูุฑุฏูุฏ
โ โ โโโ template.go # Template mode (ุงุณุชุจุฏุงู ุงูุฅุทุงุฑ ุงูู
ุณุฌูู)
โ โ โโโ testdata/ # ุฅุทุงุฑุงุช ู
ุณุฌููุฉ ู
ู ุงูู
ุชุตูุญ
โ โโโ transport/ # gorilla/websocket dialer
โ โโโ upload/ # rupload.meta.ai (lowercase headers)
โ โโโ generation/ # SSE parsing
โโโ cmd/livecheck/ # ุงุฎุชุจุงุฑุงุช ุญูุฉ
โโโ cmd/metaai-server/ # ุฎุงุฏู
API proxy (OpenAI + Anthropic)
โโโ cmd/metaai-rest/ # ุฎุงุฏู
REST API
โโโ proxy/ # ุทุจูุฉ ุงูู HTTP proxy (types, handlers, SSE)
โโโ rest/ # ุทุจูุฉ ุงูู REST API (handlers, async jobs)
โโโ examples/ # ุฃู
ุซูุฉ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ ุฅุทุงุฑ ู
ุณุฌูู โ โโโบ โ ุงุณุชุจุฏุงู โ โโโบ โ ุฅุทุงุฑ ุฌุฏูุฏ โ
โ ู
ู ุงูู
ุชุตูุญ โ โ ุงููุต + ID โ โ ุฌุงูุฒ ููุฅุฑุณุงูโ
โ โ โ + attachmentโ โ โ
โ โ ุดุบุงู โ โ ููุท โ โ โ ุดุบุงู โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ โ
โ //go:embed โ WebSocket
โ (ู
ุถู
ูู ูู ุงูููุฏ) โ ุฅุฑุณุงู
โผ โผ
testdata/ gateway.meta.ai
template_frame.b64 โ ุฑุฏ ููุฑู โ
# 179 ุงุฎุชุจุงุฑ ูุญุฏุฉ
go test ./...
# ุงุฎุชุจุงุฑุงุช ุญูุฉ (ุชุชุทูุจ cookies ุตุงูุญุฉ)
META_AI_DATR=... META_AI_ECTO_1_SESS=... META_AI_ACCESS_TOKEN=ecto1:... \
go run ./cmd/livecheck
# ุชูุฑูุฑ ุงูุชุบุทูุฉ
go test ./... -coverโ
Chat: "HELLO123" (ุฑุฏ ู
ุทุงุจู)
โ
Upload: mediaID=2019608138695944
โ
Analyze: "Green" (ุตูุฑุฉ ุฎุถุฑุงุก โ AI ุดุงููุง ููุตููุง)
โ
Generate: ุชู
ุงูุฅุฑุณุงู ูุงูู
ุนุงูุฌุฉ
โ
Stream: 39 chunks / 932 chars
โ
History: success=true
โ
Topics: NewTopic/SetTopic/Chat/ListTopics
MIT
- ุงูููุฏุณุฉ ุงูุนูุณูุฉ ููุจุฑูุชูููู: ุงูุชูุงุท ุญู ู ู ุงูู ุชุตูุญ (2026-06-19)