Developer docsInformational
Chat completions docs
POST /v1/chat/completions: campuri, streaming, tool calling, JSON mode.
Raspuns scurt
POST /v1/chat/completions accepta `model`, `messages`, `stream`, `tools`, `tool_choice`, `response_format`, `max_tokens`, `temperature`. Raspunsul standard contine `choices[0].message`.
Problema concreta
Echipele cer reference rapida pentru campurile suportate, mai ales pentru tool calling și JSON mode.
Cum o rezolva Router by MP
Reference detaliata cu exemple curl, Node și Python. Erori comune (401, 403, 429) și patterns de retry.
Fluxuri uzuale
- POST cu model + messages.
- stream:true pentru SSE.
- tools pentru function calling.
- response_format json_object pentru output structurat.
| Control | De ce conteaza |
|---|---|
| OpenAI 1:1 | Forma identica. |
| Streaming SSE | Chunks normalizate. |
| JSON mode | response_format json_object. |
curl chat completionsbash
curl https://api.megapromoting.com/v1/chat/completions \
-H "Authorization: Bearer $ROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4-mini",
"messages": [
{"role":"system","content":"Esti asistent B2B."},
{"role":"user","content":"Cum integrez gateway-ul?"}
],
"stream": false,
"max_tokens": 256
}'Reguli si limite
- Context window. Per model; verifica /models.
- max_tokens. Limiteaza output cost.
- Tool calls. Server-side validation obligatorie.
Integrare rapida
Foloseste endpointul https://api.megapromoting.com/v1, trimite cheia caAuthorization: Bearer <router_api_key> si verifica pagina/modelsinainte de productie.