Upload a media source
curl --request POST \
--url https://inference.magica.com/v1/uploads \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://example.invalid/conformance"
}
'import requests
url = "https://inference.magica.com/v1/uploads"
payload = { "url": "https://example.invalid/conformance" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: 'https://example.invalid/conformance'})
};
fetch('https://inference.magica.com/v1/uploads', 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/uploads",
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([
'url' => 'https://example.invalid/conformance'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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/uploads"
payload := strings.NewReader("{\n \"url\": \"https://example.invalid/conformance\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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/uploads")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://example.invalid/conformance\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://inference.magica.com/v1/uploads")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://example.invalid/conformance\"\n}"
response = http.request(request)
puts response.read_body{
"url": "<string>",
"media_type": "image",
"filename": "<string>",
"metadata": {}
}{
"error": "<string>",
"code": "source_invalid_url",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "source_invalid_url",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}Generated Media
Upload media
Import a URL, data URI, or raw base64 media source into permanent storage for the authenticated API key owner.
POST
/
v1
/
uploads
Upload a media source
curl --request POST \
--url https://inference.magica.com/v1/uploads \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"url": "https://example.invalid/conformance"
}
'import requests
url = "https://inference.magica.com/v1/uploads"
payload = { "url": "https://example.invalid/conformance" }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({url: 'https://example.invalid/conformance'})
};
fetch('https://inference.magica.com/v1/uploads', 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/uploads",
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([
'url' => 'https://example.invalid/conformance'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"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/uploads"
payload := strings.NewReader("{\n \"url\": \"https://example.invalid/conformance\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
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/uploads")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"url\": \"https://example.invalid/conformance\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://inference.magica.com/v1/uploads")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"url\": \"https://example.invalid/conformance\"\n}"
response = http.request(request)
puts response.read_body{
"url": "<string>",
"media_type": "image",
"filename": "<string>",
"metadata": {}
}{
"error": "<string>",
"code": "source_invalid_url",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "source_invalid_url",
"retryable": true,
"details": [
{}
]
}{
"error": "<string>",
"code": "<string>",
"retryable": true,
"details": [
{}
]
}Uploads a media source from a public URL, data URI, or raw base64 payload and
returns its permanent Magica URL and detected media metadata.
Authorization
Request
Provide exactly one source:url: a public HTTPS media URL or a base64 data URI. Remote URLs must be reachable without interactive authentication.data_uri: a base64 data URI.base64: raw base64 bytes;content_typeis required with this form.
media_type, filename, and folder. folder defaults
to mcp-uploads; setting it to media-library only changes the storage folder
and does not create a media-library catalog record.
Examples
- URL
- Data URI
- Raw base64
curl -X POST https://inference.magica.com/v1/uploads \
-H "Authorization: Bearer $MAGICA_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"url": "https://example.com/image.png",
"filename": "reference-image.png"
}'
curl -X POST https://inference.magica.com/v1/uploads \
-H "Authorization: Bearer $MAGICA_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"data_uri": "data:image/png;base64,iVBORw0KGgoAAA...",
"filename": "inline-data-uri.png"
}'
curl -X POST https://inference.magica.com/v1/uploads \
-H "Authorization: Bearer $MAGICA_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"base64": "iVBORw0KGgoAAA...",
"content_type": "image/png",
"filename": "inline-image.png"
}'
Response
Errors
| Status | Reason |
|---|---|
400 | The source URL or upload request is invalid or inaccessible |
401 | Missing or invalid API key |
402 | Insufficient credits |
403 | The API key is not allowed to upload media |
413 | The source exceeds the upload size limit |
429 | Upload rate limit exceeded |
500 | The source could not be fetched or stored |
503 | Upload service temporarily unavailable |
Authorizations
Body
application/json
- Option 1
- Option 2
- Option 3
Provide exactly one of url, data_uri, or base64. URL sources may be public HTTPS media URLs or base64 data URIs; explicitly enabled non-production localhost fixtures may use HTTP. Raw base64 also requires content_type.
Was this page helpful?