Ruby + PixelPanda API

Remove Background with Ruby

Remove image backgrounds from Ruby with Net::HTTP. No gems beyond stdlib. Works with Rails, Sinatra, and scripts.

$ # No gems needed — uses Ruby stdlib (net/http, json)

Ruby examples — copy and go

Each example is self-contained. Copy the one that matches your use case.

Quick start

Basic background removal using Ruby stdlib.

require "net/http"
require "json"
require "uri"

API_KEY = "pk_live_your_api_key"
uri = URI("https://pixelpanda.ai/api/v1/remove-background")

boundary = "----Ruby#{rand(1000000)}"
body = ""
body += "--#{boundary}
"
body += "Content-Disposition: form-data; name="file"; filename="product.jpg"
"
body += "Content-Type: image/jpeg

"
body += File.binread("product.jpg")
body += "
--#{boundary}--
"

request = Net::HTTP::Post.new(uri)
request["Authorization"] = "Bearer #{API_KEY}"
request["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
request.body = body

response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
data = JSON.parse(response.body)
puts data["image_url"]

Rails controller

Accept uploads and process in a Rails app.

# app/controllers/images_controller.rb
class ImagesController < ApplicationController
  def remove_background
    uploaded = params[:image]
    return render json: { error: "No image" }, status: 400 unless uploaded

    uri = URI("https://pixelpanda.ai/api/v1/remove-background")
    boundary = "----Rails#{SecureRandom.hex(8)}"

    body = ""
    body += "--#{boundary}
"
    body += "Content-Disposition: form-data; name="file"; filename="#{uploaded.original_filename}"
"
    body += "Content-Type: #{uploaded.content_type}

"
    body += uploaded.read
    body += "
--#{boundary}--
"

    request = Net::HTTP::Post.new(uri)
    request["Authorization"] = "Bearer #{ENV['PIXELPANDA_API_KEY']}"
    request["Content-Type"] = "multipart/form-data; boundary=#{boundary}"
    request.body = body

    response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) { |http| http.request(request) }
    render json: JSON.parse(response.body)
  end
end

Response format

Every successful request returns this JSON. The image_url is a permanent link to the transparent PNG.

{
    "success": true,
    "image_url": "https://pub-xxx.r2.dev/results/abc123.png",
    "credits_remaining": 199
}
FieldTypeDescription
successbooleantrue if background was removed successfully
image_urlstringURL to the transparent PNG result (permanent, hosted on CDN)
credits_remainingintegerHow many credits are left on your account

Error codes

CodeMeaning
200Success
401Invalid API key
402Out of credits
429Rate limited

Common questions

No. Uses Ruby's built-in net/http and json. Zero dependencies.
Yes — see the Rails controller example above.
1 credit per image (~$0.029). $10 Impulse pack (50 credits, one-time) or $7.99/week subscription for 280 credits/week (cancel anytime).

Start removing backgrounds with Ruby

280 credits/week for $7.99. Copy the code above and go.

Get Your API Key