Code Examples
Tabbed examples for common tasks using cURL, Node.js, and PHP. Use your API key with Authorization: Bearer ...
unless you initialize a widget session.
1) Chat (OpenAI-compatible)
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" -H "Content-Type: application/json" \
-X POST https://app.synaplan.com/api.php/v1/chat/completions \
-d '{"model":"gpt-4.1","messages":[{"role":"user","content":"Hello"}]}'
2) Chat streaming
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" -H "Content-Type: application/json" \
-X POST https://app.synaplan.com/api.php/v1/chat/completions \
-d '{"model":"gpt-4.1","stream":true,"messages":[{"role":"user","content":"Stream please"}]}'
3) Image Generation
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" -H "Content-Type: application/json" \
-X POST https://app.synaplan.com/api.php/v1/images/generations \
-d '{"prompt":"cat wearing sunglasses, vector style"}'
4) Internet Screenshot (REST)
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" \
-F "action=messageNew" -F "message=Take a screenshot of https://example.com" \
https://app.synaplan.com/api.php
5) REST chat + SSE
last=$(curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" \
-F action=messageNew -F message="Who are you?" https://app.synaplan.com/api.php | jq -r '.lastIds[0]')
curl -N -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" \
-F action=chatStream -F lastIds="$last" https://app.synaplan.com/api.php
6) Translate snippet (REST)
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" -X POST \
-F action=snippetTranslate -F source_text="Hello" -F dest_lang=de \
https://app.synaplan.com/api.php
7) Upload RAG file (REST)
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" -X POST \
-F action=ragUpload -F files[]=@/path/to/manual.pdf \
https://app.synaplan.com/api.php
8) Models list
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" https://app.synaplan.com/api.php/v1/models
9) Audio transcription
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" -X POST \
-F file=@/path/to/audio.m4a \
https://app.synaplan.com/api.php/v1/audio/transcriptions
10) Image analysis
curl -sS -H "Authorization: Bearer $SYNAPLAN_API_KEY" -X POST \
-F image=@/path/to/photo.jpg \
https://app.synaplan.com/api.php/v1/images/analysis
Setup
npm install axios form-data
1) Chat (OpenAI-compatible)
const axios = require('axios');
async function chat() {
const res = await axios.post('https://app.synaplan.com/api.php/v1/chat/completions', {
model: 'gpt-4.1',
messages: [{ role: 'user', content: 'Hello' }]
}, {
headers: { Authorization: `Bearer ${process.env.SYNAPLAN_API_KEY}` }
});
console.log(res.data);
}
chat();
2) REST message + SSE
const axios = require('axios');
const FormData = require('form-data');
async function restSSE(){
const fd = new FormData();
fd.append('action','messageNew');
fd.append('message','Who are you?');
const res = await axios.post('https://app.synaplan.com/api.php', fd, {
headers: { Authorization: `Bearer ${process.env.SYNAPLAN_API_KEY}`, ...fd.getHeaders() }
});
const last = res.data.lastIds[0];
// SSE
const sseFd = new FormData();
sseFd.append('action','chatStream');
sseFd.append('lastIds', String(last));
const resp = await axios.post('https://app.synaplan.com/api.php', sseFd, {
headers: { Authorization: `Bearer ${process.env.SYNAPLAN_API_KEY}`, ...sseFd.getHeaders() },
responseType: 'stream'
});
resp.data.on('data', chunk => process.stdout.write(chunk.toString()));
}
restSSE();
3) Image generation
const axios = require('axios');
async function gen(){
const res = await axios.post('https://app.synaplan.com/api.php/v1/images/generations', { prompt: 'cat in sunglasses' }, {
headers: { Authorization: `Bearer ${process.env.SYNAPLAN_API_KEY}` }
});
console.log(res.data);
}
gen();
1) Chat (OpenAI-compatible)
<?php
$ch = curl_init('https://app.synaplan.com/api.php/v1/chat/completions');
$payload = json_encode([
'model' => 'gpt-4.1',
'messages' => [ ['role'=>'user','content'=>'Hello'] ]
]);
curl_setopt_array($ch, [
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('SYNAPLAN_API_KEY'),
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => $payload,
CURLOPT_RETURNTRANSFER => true
]);
$res = curl_exec($ch);
curl_close($ch);
echo $res;
2) REST message
<?php
$ch = curl_init('https://app.synaplan.com/api.php');
$data = ['action'=>'messageNew','message'=>'Hello from PHP'];
curl_setopt_array($ch, [
CURLOPT_POST => 1,
CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('SYNAPLAN_API_KEY') ],
CURLOPT_POSTFIELDS => $data,
CURLOPT_RETURNTRANSFER => true
]);
echo curl_exec($ch);
curl_close($ch);