How to pass a base64 image to the Infer API endpoint
In the documentation for the API, it says to pass base64 images through the body of our POST request.

response =, params=params, data=base64_image)

This is the request code and all it returns is error code 400. params is my API key. What do I do?

Hi @george_bibu , what is the value of roboflow_url?

Can you make sure that roboflow_url=f'{project_id}/{version_id}

Yes, that is the value of my roboflow_url.

Hello? Were you able to find anything out? I would really like to know if it’s possible to access the endpoint in this manner or not, because I really don’t want to waste time trying to do something that’s impossible.


import base64
import os
from PIL import Image
import requests

API_KEY = os.environ["API_KEY"]
IMAGE_PATH = "image.jpg"

def encode_bas64(image_path):
    with open(image_path, "rb") as image:
        x =
        image_string = base64.b64encode(x)

    return image_string.decode("ascii")

def do_request():
    api_key = API_KEY
    infer_payload = {
        "image": {
            "type": "base64",
            "value": encode_bas64(IMAGE_PATH),
        "api_key": api_key,
    roboflow_url = f"{PROJECT_ID}/{VERSION_ID}",
    response =, json=infer_payload)

If that doesn’t work, try using the inference client: