For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://modelgates.ai/docs/_mcp/server.

Image Inputs

Requests with images, to multimodel models, are available via the /api/v1/chat/completions API with a multi-part messages parameter. The image_url can either be a URL or a base64-encoded image. Note that multiple images can be sent in separate content array entries. The number of images you can send in a single request varies per provider and per model. Due to how the content is parsed, we recommend sending the text prompt first, then the images. If the images must come first, we recommend putting it in the system prompt.

ModelGates supports both direct URLs and base64-encoded data for images:

  • URLs: More efficient for publicly accessible images as they don't require local encoding
  • Base64: Required for local files or private images that aren't publicly accessible

Using Image URLs

Here's how to send an image using a URL:

typescript
import { ModelGates } from '@modelgates/sdk'; const modelgates = new ModelGates({  apiKey: '{}',}); const result = await modelgates.chat.send({  model: '{}',  messages: [    {      role: 'user',      content: [        {          type: 'text',          text: "What's in this image?",        },        {          type: 'image_url',          imageUrl: {            url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg',          },        },      ],    },  ],  stream: false,}); console.log(result);
python
import requestsimport json url = "https://modelgates.ai/api/v1/chat/completions"headers = {    "Authorization": f"Bearer {API_KEY_REF}",    "Content-Type": "application/json"} messages = [    {        "role": "user",        "content": [            {                "type": "text",                "text": "What's in this image?"            },            {                "type": "image_url",                "image_url": {                    "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"                }            }        ]    }] payload = {    "model": "{{MODEL}}",    "messages": messages} response = requests.post(url, headers=headers, json=payload)print(response.json())
typescript
const response = await fetch('https://modelgates.ai/api/v1/chat/completions', {  method: 'POST',  headers: {    Authorization: `Bearer ${API_KEY_REF}`,    'Content-Type': 'application/json',  },  body: JSON.stringify({    model: '{{MODEL}}',    messages: [      {        role: 'user',        content: [          {            type: 'text',            text: "What's in this image?",          },          {            type: 'image_url',            image_url: {              url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg',            },          },        ],      },    ],  }),}); const data = await response.json();console.log(data);

Using Base64 Encoded Images

For locally stored images, you can send them using base64 encoding. Here's how to do it:

typescript
import { ModelGates } from '@modelgates/sdk';import * as fs from 'fs'; const modelgates = new ModelGates({  apiKey: '{}',}); async function encodeImageToBase64(imagePath: string): Promise<string> {  const imageBuffer = await fs.promises.readFile(imagePath);  const base64Image = imageBuffer.toString('base64');  return `data:image/jpeg;base64,$`;} // Read and encode the imageconst imagePath = 'path/to/your/image.jpg';const base64Image = await encodeImageToBase64(imagePath); const result = await modelgates.chat.send({  model: '{}',  messages: [    {      role: 'user',      content: [        {          type: 'text',          text: "What's in this image?",        },        {          type: 'image_url',          imageUrl: {            url: base64Image,          },        },      ],    },  ],  stream: false,}); console.log(result);
python
import requestsimport jsonimport base64from pathlib import Path def encode_image_to_base64(image_path):    with open(image_path, "rb") as image_file:        return base64.b64encode(image_file.read()).decode('utf-8') url = "https://modelgates.ai/api/v1/chat/completions"headers = {    "Authorization": f"Bearer {API_KEY_REF}",    "Content-Type": "application/json"} # Read and encode the imageimage_path = "path/to/your/image.jpg"base64_image = encode_image_to_base64(image_path)data_url = f"data:image/jpeg;base64," messages = [    {        "role": "user",        "content": [            {                "type": "text",                "text": "What's in this image?"            },            {                "type": "image_url",                "image_url": {                    "url": data_url                }            }        ]    }] payload = {    "model": "{{MODEL}}",    "messages": messages} response = requests.post(url, headers=headers, json=payload)print(response.json())
typescript
async function encodeImageToBase64(imagePath: string): Promise<string> {  const imageBuffer = await fs.promises.readFile(imagePath);  const base64Image = imageBuffer.toString('base64');  return `data:image/jpeg;base64,$`;} // Read and encode the imageconst imagePath = 'path/to/your/image.jpg';const base64Image = await encodeImageToBase64(imagePath); const response = await fetch('https://modelgates.ai/api/v1/chat/completions', {  method: 'POST',  headers: {    Authorization: `Bearer ${API_KEY_REF}`,    'Content-Type': 'application/json',  },  body: JSON.stringify({    model: '{{MODEL}}',    messages: [      {        role: 'user',        content: [          {            type: 'text',            text: "What's in this image?",          },          {            type: 'image_url',            image_url: {              url: base64Image,            },          },        ],      },    ],  }),}); const data = await response.json();console.log(data);

Supported image content types are:

  • image/png
  • image/jpeg
  • image/webp
  • image/gif