Skip to main content

Upload Image from URL

Upload an image by providing its URL. The server fetches, caches, and moderates the image. Returns a CachedImage with the hosted URL and safety score.

Endpoint and Auth​

Use the public gated endpoint, https://pin.intuition.systems/v1/graphql, with an apikey request header. Keep the key in a trusted server runtime.

Mutation Structure​

mutation UploadImageFromUrl($image: UploadImageFromUrlInput!) {
uploadImageFromUrl(image: $image) {
images {
url
original_url
safe
score
model
created_at
}
}
}

Variables​

The mutation takes an image argument with the UploadImageFromUrlInput type:

FieldTypeRequiredDescription
urlStringYesURL of the image to upload
{
"image": {
"url": "https://example.com/images/logo.png"
}
}

Response Fields​

Returns UploadImageFromUrlOutput containing an images array of CachedImage objects:

FieldTypeDescription
images[CachedImage!]!Array of cached image results
images[].urlString!Hosted image URL
images[].original_urlString!Original source URL
images[].safeBoolean!Whether the image passed moderation
images[].scorejsonbModeration safety score details
images[].modelStringModeration model used
images[].created_attimestamptz!Upload timestamp

Expected Response​

{
"data": {
"uploadImageFromUrl": {
"images": [
{
"url": "https://cdn.example.com/images/abc123.png",
"original_url": "https://example.com/images/logo.png",
"safe": true,
"score": null,
"model": null,
"created_at": "2024-01-15T10:30:00Z"
}
]
}
}
}

Use Cases​

Import External Images​

import { GraphQLClient } from 'graphql-request';
import { PIN_API_URL } from '@0xintuition/graphql';

const client = new GraphQLClient(PIN_API_URL, {
headers: {
apikey: process.env.INTUITION_PIN_API_KEY!,
},
});

async function importExternalImage(imageUrl: string) {
const mutation = `
mutation UploadImageFromUrl($image: UploadImageFromUrlInput!) {
uploadImageFromUrl(image: $image) {
images {
url
safe
}
}
}
`;

const result = await client.request(mutation, {
image: { url: imageUrl },
});

const cached = result.uploadImageFromUrl.images[0];
if (!cached) {
throw new Error('Image host could not be fetched');
}

if (!cached.safe) {
throw new Error('Image failed moderation check');
}
return cached.url;
}