Skip to main content
POST
Create a chat completion
Creates a response from a conversation represented as a messages array. Use this endpoint for chat history, tool calls, images, and PDFs.

Authorization

string
required
Magica API key in the form Bearer gx_your_api_key.

Body

string
required
Model ID from the language-model catalog.
array
required
Conversation messages with developer, system, user, assistant, or tool roles. Send previous turns again when the next answer depends on them.
boolean
default:"false"
Omit or set false for one complete JSON object. Set true for server-sent events.
integer
Maximum output tokens. Must be at least 1 and no greater than the model’s advertised output limit.
number
Sampling temperature. Lower values are more deterministic.
array
Function definitions the model may call.
string | object
Controls whether the model may call a tool, must call one, or must call a named function.

Direct JSON request

Direct JSON response

Stream the response

Add "stream": true and read each SSE data: frame. The final usage chunk is followed by data: [DONE].

Images and PDFs

Inside a user message, use:
  • {"type":"image_url","image_url":{"url":"https://..."}} for an image.
  • {"type":"file","file":{"filename":"report.pdf","file_data":"https://..."}} for a PDF.
See Images, PDFs, and attachments for complete examples in every wire format.

Errors