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.
Install
Code examples
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
endAPI reference
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
}| Field | Type | Description |
|---|---|---|
| success | boolean | true if background was removed successfully |
| image_url | string | URL to the transparent PNG result (permanent, hosted on CDN) |
| credits_remaining | integer | How many credits are left on your account |
Error codes
| Code | Meaning |
|---|---|
| 200 | Success |
| 401 | Invalid API key |
| 402 | Out of credits |
| 429 | Rate limited |
FAQ
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).
More languages
By platform
Start removing backgrounds with Ruby
280 credits/week for $7.99. Copy the code above and go.
Get Your API Key