Create a response
curl --request POST \
--url https://inference.magica.com/v1/responses \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"input": {},
"instructions": "<string>",
"max_output_tokens": 123,
"stream": true,
"tools": [
{}
],
"tool_choice": {}
}
'import requests
url = "https://inference.magica.com/v1/responses"
payload = {
"model": "<string>",
"input": {},
"instructions": "<string>",
"max_output_tokens": 123,
"stream": True,
"tools": [{}],
"tool_choice": {}
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
input: {},
instructions: '<string>',
max_output_tokens: 123,
stream: true,
tools: [{}],
tool_choice: {}
})
};
fetch('https://inference.magica.com/v1/responses', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://inference.magica.com/v1/responses",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'input' => [
],
'instructions' => '<string>',
'max_output_tokens' => 123,
'stream' => true,
'tools' => [
[
]
],
'tool_choice' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://inference.magica.com/v1/responses"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": {},\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 123,\n \"stream\": true,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://inference.magica.com/v1/responses")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": {},\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 123,\n \"stream\": true,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://inference.magica.com/v1/responses")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"input\": {},\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 123,\n \"stream\": true,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {}\n}"
response = http.request(request)
puts response.read_bodyLLM Gateway
Create a response
Generate one complete Responses-style result or stream item and text events.
POST
/
v1
/
responses
Create a response
curl --request POST \
--url https://inference.magica.com/v1/responses \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "<string>",
"input": {},
"instructions": "<string>",
"max_output_tokens": 123,
"stream": true,
"tools": [
{}
],
"tool_choice": {}
}
'import requests
url = "https://inference.magica.com/v1/responses"
payload = {
"model": "<string>",
"input": {},
"instructions": "<string>",
"max_output_tokens": 123,
"stream": True,
"tools": [{}],
"tool_choice": {}
}
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: '<string>',
input: {},
instructions: '<string>',
max_output_tokens: 123,
stream: true,
tools: [{}],
tool_choice: {}
})
};
fetch('https://inference.magica.com/v1/responses', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://inference.magica.com/v1/responses",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'model' => '<string>',
'input' => [
],
'instructions' => '<string>',
'max_output_tokens' => 123,
'stream' => true,
'tools' => [
[
]
],
'tool_choice' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://inference.magica.com/v1/responses"
payload := strings.NewReader("{\n \"model\": \"<string>\",\n \"input\": {},\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 123,\n \"stream\": true,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {}\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://inference.magica.com/v1/responses")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"model\": \"<string>\",\n \"input\": {},\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 123,\n \"stream\": true,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://inference.magica.com/v1/responses")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"model\": \"<string>\",\n \"input\": {},\n \"instructions\": \"<string>\",\n \"max_output_tokens\": 123,\n \"stream\": true,\n \"tools\": [\n {}\n ],\n \"tool_choice\": {}\n}"
response = http.request(request)
puts response.read_bodyCreates a response from a text string or an array of input items. Use
This stream does not use a
instructions for developer guidance and input items for messages, images,
PDFs, function calls, and function-call results.
Authorization
Body
Model ID from the language-model catalog.
A text prompt or an array of message, function-call, and function-call-output
items.
Omit or set
false for one complete response object. Set true for named SSE
events.Direct JSON request
- cURL
- Node.js
- Python
curl https://inference.magica.com/v1/responses \
-H "Authorization: Bearer $MAGICA_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "openai/gpt-5.4-mini",
"instructions": "Keep the answer concise.",
"input": "Reply with exactly: hello"
}'
const response = await fetch("https://inference.magica.com/v1/responses", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.MAGICA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "openai/gpt-5.4-mini",
input: "Reply with exactly: hello",
}),
});
if (!response.ok) throw new Error(await response.text());
const result = await response.json();
console.log(result.output[0].content[0].text);
import os, requests
response = requests.post(
"https://inference.magica.com/v1/responses",
headers={"Authorization": f"Bearer {os.environ['MAGICA_API_KEY']}"},
json={
"model": "openai/gpt-5.4-mini",
"input": "Reply with exactly: hello",
},
timeout=120,
)
response.raise_for_status()
print(response.json()["output"][0]["content"][0]["text"])
Direct JSON response
{
"id": "resp_123",
"object": "response",
"model": "openai/gpt-5.4-mini",
"status": "completed",
"output": [
{
"type": "message",
"status": "completed",
"role": "assistant",
"content": [{ "type": "output_text", "text": "hello", "annotations": [] }]
}
],
"usage": { "input_tokens": 20, "output_tokens": 1, "total_tokens": 21 }
}
Stream the response
Add"stream": true. A normal result starts with response.created, emits
output-item and text events, and ends with response.completed.
event: response.created
data: {"type":"response.created","response":{"id":"resp_123","object":"response","status":"in_progress","output":[]}}
event: response.output_text.delta
data: {"type":"response.output_text.delta","item_id":"msg_123","output_index":0,"content_index":0,"delta":"hello"}
event: response.completed
data: {"type":"response.completed","response":{"id":"resp_123","object":"response","status":"completed","output":[],"usage":{"input_tokens":20,"output_tokens":1,"total_tokens":21}}}
[DONE] sentinel.
Images and PDFs
Within a message item’scontent array:
- Image:
{"type":"input_image","image_url":"https://..."} - PDF:
{"type":"input_file","filename":"report.pdf","file_url":"https://..."}
input_file also accepts inline file_data. Prefer a URL for large files.
Errors
| Status | Reason |
|---|---|
400 | Invalid request or unsupported input item |
401 | Missing or invalid API key |
402 | Insufficient credits |
403 | Access token lacks the llm:inference scope |
404 | Model ID was not found |
413 | Request exceeds the direct transport or selected model limit |
429 | Rate limit reached; retry using Retry-After |
502 | Model service could not complete the request |
503 | Credit authorization is temporarily unavailable |
529 | Model service is temporarily overloaded |
Was this page helpful?