Chatbot API: chat completions prin Router by MP
Endpoint POST /v1/chat/completions prin Router by MP: streaming, tool calling, multi-turn, JSON mode.
Raspuns scurt
Pentru chatbots folosesti POST /v1/chat/completions cu structura OpenAI standard; suporta streaming SSE, tool calling, multi-turn și JSON mode.
Problema concreta
Echipele care construiesc chatbots trebuie sa stie ce capabilitati au endpoint-urile, cum se gestioneaza streamingul și cum se face tool calling pentru integrari reale.
Cum o rezolva Router by MP
Router by MP expune endpoint identic cu OpenAI Chat Completions; toate modelele GPT live suporta multi-turn cu rol system/user/assistant. Streaming SSE este disponibil pentru toate modelele de chat.
Fluxuri uzuale
- Prompt system + history mesaje + user message nou.
- Streaming SSE pentru UI live.
- Tool calling pentru actiuni externe (search, calendar, DB).
- JSON mode pentru output structurat (response_format).
Modele recomandate
gpt-5.4-minigpt-5.4-nanogpt-5.4-progemini-flash-latest
Disponibilitatea reala se verifica live in /models.
| Control | De ce conteaza |
|---|---|
| OpenAI compatible | Forma de cerere și raspuns identica cu OpenAI Chat Completions. |
| Tool calling | Modelele GPT live accepta tools și tool_choice. |
| JSON mode | response_format json_object pentru output structurat. |
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 pentru CRM."},
{"role":"user","content":"Cum scriu un lead nou?"}
],
"stream": false
}'Reguli si limite
- Disponibilitate model. Anumite modele pot avea capacitati partiale; verifica /models.
- Context window. Variaza per model; pastreaza history sub limita.
- Cost. Output tokens conteaza; folosește max_tokens conservator.
Integrare rapida
Foloseste endpointul https://api.megapromoting.com/v1, trimite cheia caAuthorization: Bearer <router_api_key> si verifica pagina/modelsinainte de productie.