Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "4.0.0"
".": "4.0.1"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configured_endpoints: 42
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/imagekit-inc%2Fimagekit-9d184cb502ab32a85db2889c796cdfebe812f2a55a604df79c85dd4b5e7e2add.yml
openapi_spec_hash: a9aa620376fce66532c84f9364209b0b
config_hash: eb4cf65a4c6b26a2901076eff5810d5d
config_hash: 71cab8223bb5610c6c7ca6e9c4cc1f89
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# Changelog

## 4.0.1 (2026-01-13)

Full Changelog: [v4.0.0...v4.0.1](https://github.com/imagekit-developer/imagekit-ruby/compare/v4.0.0...v4.0.1)

### Bug Fixes

* better thread safety via early initializing SSL store during HTTP client creation ([2bc0835](https://github.com/imagekit-developer/imagekit-ruby/commit/2bc0835981c29b717f0ad3a7d78c3c78027874e0))
* calling `break` out of streams should be instantaneous ([55bf4a9](https://github.com/imagekit-developer/imagekit-ruby/commit/55bf4a9b768f18f4adad903b2c9d93178a670151))
* issue where json.parse errors when receiving HTTP 204 with nobody ([dd32cb1](https://github.com/imagekit-developer/imagekit-ruby/commit/dd32cb1572bc155db85ed898011374889996b3fd))


### Chores

* bump dependency version and update sorbet types ([8d89fb2](https://github.com/imagekit-developer/imagekit-ruby/commit/8d89fb2c1654420f83bb7efedcc9056c5a7e3c79))
* **client:** send user-agent header ([796027d](https://github.com/imagekit-developer/imagekit-ruby/commit/796027d185c93067c32bac98323d8a82aeaf9bfe))
* explicitly require "base64" gem ([1b4181d](https://github.com/imagekit-developer/imagekit-ruby/commit/1b4181d4e57d2c12306f6d3f43b832f63ab68053))
* **internal:** codegen related update ([3a93def](https://github.com/imagekit-developer/imagekit-ruby/commit/3a93def2d09609b359824a627183833ae59d74e1))
* **internal:** codegen related update ([4c161f0](https://github.com/imagekit-developer/imagekit-ruby/commit/4c161f048927df137a12d33a5a1b79af1c561b8b))
* move `cgi` into dependencies for ruby 4 ([54261ef](https://github.com/imagekit-developer/imagekit-ruby/commit/54261ef9f24e206d2180dc0a205464154af4c3ed))


### Documentation

* prominently feature MCP server setup in root SDK readmes ([777f8cf](https://github.com/imagekit-developer/imagekit-ruby/commit/777f8cf5cc692eed3e8f6217caf25a85d17201f7))

## 4.0.0 (2025-11-03)

Full Changelog: [v0.0.1...v4.0.0](https://github.com/imagekit-developer/imagekit-ruby/compare/v0.0.1...v4.0.0)
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ group :development do
gem "sorbet"
gem "steep"
gem "syntax_tree"
# TODO: using a fork for now, the prettier below has a bug
gem "syntax_tree-rbs", github: "stainless-api/syntax_tree-rbs", branch: "main"
gem "syntax_tree-rbs", github: "ruby-syntax-tree/syntax_tree-rbs", branch: "main"
gem "tapioca"
end

Expand Down
8 changes: 5 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: https://github.com/stainless-api/syntax_tree-rbs.git
revision: c30b50219918be7cfe3ef803a00b59d1e77fcada
remote: https://github.com/ruby-syntax-tree/syntax_tree-rbs.git
revision: f94bc3060682ffbd126e4d5086ffedc89073d626
branch: main
specs:
syntax_tree-rbs (1.0.0)
Expand All @@ -11,7 +11,8 @@ GIT
PATH
remote: .
specs:
imagekitio (4.0.0)
imagekitio (4.0.1)
cgi
connection_pool

GEM
Expand Down Expand Up @@ -42,6 +43,7 @@ GEM
base64 (0.3.0)
benchmark (0.5.0)
bigdecimal (3.3.1)
cgi (0.5.1)
concurrent-ruby (1.3.5)
connection_pool (2.5.4)
console (1.34.2)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2025 ImageKit
Copyright 2026 Image Kit

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

The ImageKit Ruby library provides convenient access to the ImageKit REST API from any Ruby 3.2.0+ application. The library supports building and transforming URLs, generating signed URLs for secure content delivery, and handling file uploads. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/imagekit-developer/imagekit-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.

## MCP Server

Use the Image Kit MCP Server to enable AI assistants to interact with this API, allowing them to explore endpoints, make test requests, and use documentation to help integrate this SDK into your application.

[![Add to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](https://cursor.com/en-US/install-mcp?name=%40imagekit%2Fapi-mcp&config=eyJjb21tYW5kIjoibnB4IiwiYXJncyI6WyIteSIsIkBpbWFnZWtpdC9hcGktbWNwIl19)
[![Install in VS Code](https://img.shields.io/badge/_-Add_to_VS_Code-blue?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiIHZpZXdCb3g9IjAgMCA0MCA0MCI+PHBhdGggZmlsbD0iI0VFRSIgZmlsbC1ydWxlPSJldmVub2RkIiBkPSJNMzAuMjM1IDM5Ljg4NGEyLjQ5MSAyLjQ5MSAwIDAgMS0xLjc4MS0uNzNMMTIuNyAyNC43OGwtMy40NiAyLjYyNC0zLjQwNiAyLjU4MmExLjY2NSAxLjY2NSAwIDAgMS0xLjA4Mi4zMzggMS42NjQgMS42NjQgMCAwIDEtMS4wNDYtLjQzMWwtMi4yLTJhMS42NjYgMS42NjYgMCAwIDEgMC0yLjQ2M0w3LjQ1OCAyMCA0LjY3IDE3LjQ1MyAxLjUwNyAxNC41N2ExLjY2NSAxLjY2NSAwIDAgMSAwLTIuNDYzbDIuMi0yYTEuNjY1IDEuNjY1IDAgMCAxIDIuMTMtLjA5N2w2Ljg2MyA1LjIwOUwyOC40NTIuODQ0YTIuNDg4IDIuNDg4IDAgMCAxIDEuODQxLS43MjljLjM1MS4wMDkuNjk5LjA5MSAxLjAxOS4yNDVsOC4yMzYgMy45NjFhMi41IDIuNSAwIDAgMSAxLjQxNSAyLjI1M3YuMDk5LS4wNDVWMzMuMzd2LS4wNDUuMDk1YTIuNTAxIDIuNTAxIDAgMCAxLTEuNDE2IDIuMjU3bC04LjIzNSAzLjk2MWEyLjQ5MiAyLjQ5MiAwIDAgMS0xLjA3Ny4yNDZabS43MTYtMjguOTQ3LTExLjk0OCA5LjA2MiAxMS45NTIgOS4wNjUtLjAwNC0xOC4xMjdaIi8+PC9zdmc+)](https://vscode.stainless.com/mcp/%7B%22name%22%3A%22%40imagekit%2Fapi-mcp%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40imagekit%2Fapi-mcp%22%5D%7D)

> Note: You may need to set environment variables in your MCP client.

## Documentation

The official [ImageKit Ruby documentation](https://imagekit.io/docs/integration/ruby) provides complete integration guides and examples.
Expand Down Expand Up @@ -45,7 +54,7 @@ To use this gem, install via Bundler by adding the following to your application
<!-- x-release-please-start-version -->

```ruby
gem "imagekitio", "~> 4.0.0"
gem "imagekitio", "~> 4.0.1"
```

<!-- x-release-please-end -->
Expand Down
1 change: 1 addition & 0 deletions imagekitio.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ Gem::Specification.new do |s|
".ignore"
]
s.extra_rdoc_files = ["README.md"]
s.add_dependency "cgi"
s.add_dependency "connection_pool"
end
2 changes: 2 additions & 0 deletions lib/imagekitio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
# Standard libraries.
# rubocop:disable Lint/RedundantRequireStatement
require "English"
require "base64"
require "cgi"
require "date"
require "erb"
require "etc"
require "json"
require "net/http"
require "openssl"
require "pathname"
require "rbconfig"
require "securerandom"
Expand All @@ -16,7 +18,7 @@
require "stringio"
require "time"
require "uri"
require "base64"

Check failure on line 21 in lib/imagekitio.rb

View workflow job for this annotation

GitHub Actions / lint

Lint/DuplicateRequire: Duplicate `require` detected.
# rubocop:enable Lint/RedundantRequireStatement

# We already ship the preferred sorbet manifests in the package itself.
Expand Down
8 changes: 7 additions & 1 deletion lib/imagekitio/internal/transport/base_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def initialize(
self.class::PLATFORM_HEADERS,
{
"accept" => "application/json",
"content-type" => "application/json"
"content-type" => "application/json",
"user-agent" => user_agent
},
headers
)
Expand All @@ -219,6 +220,11 @@ def initialize(
# @return [Hash{String=>String}]
private def auth_headers = {}

# @api private
#
# @return [String]
private def user_agent = "#{self.class.name}/Ruby #{Imagekitio::VERSION}"

# @api private
#
# @return [String]
Expand Down
41 changes: 17 additions & 24 deletions lib/imagekitio/internal/transport/pooled_net_requester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ class PooledNetRequester
class << self
# @api private
#
# @param cert_store [OpenSSL::X509::Store]
# @param url [URI::Generic]
#
# @return [Net::HTTP]
def connect(url)
def connect(cert_store:, url:)
port =
case [url.port, url.scheme]
in [Integer, _]
Expand All @@ -34,18 +35,7 @@ def connect(url)
_1.use_ssl = %w[https wss].include?(url.scheme)
_1.max_retries = 0

# Temporary workaround for SSL verification issue on some
# platforms. Similar to: https://github.com/stripe/stripe-ruby/pull/397
# Without this fix you may see errors like:
# .rbenv/versions/3.2.0/lib/ruby/3.2.0/net/protocol.rb:46:in `connect_nonblock':
# SSL_connect returned=1 errno=0 peeraddr=52.23.130.57:443 state=error:
# certificate verify failed (unable to get certificate CRL) (OpenSSL::SSL::SSLError)
if _1.use_ssl?
cert_store = OpenSSL::X509::Store.new
cert_store.set_default_paths
_1.cert_store = cert_store
_1.verify_mode = OpenSSL::SSL::VERIFY_PEER
end
(_1.cert_store = cert_store) if _1.use_ssl?
end
end

Expand Down Expand Up @@ -115,7 +105,7 @@ def build_request(request, &blk)
pool =
@mutex.synchronize do
@pools[origin] ||= ConnectionPool.new(size: @size) do
self.class.connect(url)
self.class.connect(cert_store: @cert_store, url: url)
end
end

Expand Down Expand Up @@ -163,17 +153,19 @@ def execute(request)
end

self.class.calibrate_socket_timeout(conn, deadline)
conn.request(req) do |rsp|
y << [req, rsp]
break if finished

rsp.read_body do |bytes|
y << bytes.force_encoding(Encoding::BINARY)
break if finished

self.class.calibrate_socket_timeout(conn, deadline)
::Kernel.catch(:jump) do
conn.request(req) do |rsp|
y << [req, rsp]
::Kernel.throw(:jump) if finished

rsp.read_body do |bytes|
y << bytes.force_encoding(Encoding::BINARY)
::Kernel.throw(:jump) if finished

self.class.calibrate_socket_timeout(conn, deadline)
end
eof = true
end
eof = true
end
end
ensure
Expand Down Expand Up @@ -205,6 +197,7 @@ def execute(request)
def initialize(size: self.class::DEFAULT_MAX_CONNECTIONS)
@mutex = Mutex.new
@size = size
@cert_store = OpenSSL::X509::Store.new.tap(&:set_default_paths)
@pools = {}
end

Expand Down
9 changes: 7 additions & 2 deletions lib/imagekitio/internal/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ def force_charset!(content_type, text:)
def decode_content(headers, stream:, suppress_error: false)
case (content_type = headers["content-type"])
in Imagekitio::Internal::Util::JSON_CONTENT
json = stream.to_a.join
return nil if (json = stream.to_a.join).empty?

begin
JSON.parse(json, symbolize_names: true)
rescue JSON::ParserError => e
Expand All @@ -667,7 +668,11 @@ def decode_content(headers, stream:, suppress_error: false)
in Imagekitio::Internal::Util::JSONL_CONTENT
lines = decode_lines(stream)
chain_fused(lines) do |y|
lines.each { y << JSON.parse(_1, symbolize_names: true) }
lines.each do
next if _1.empty?

y << JSON.parse(_1, symbolize_names: true)
end
end
in %r{^text/event-stream}
lines = decode_lines(stream)
Expand Down
2 changes: 2 additions & 0 deletions lib/imagekitio/models/unsafe_unwrap_webhook_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Models
module UnsafeUnwrapWebhookEvent
extend Imagekitio::Internal::Type::Union

discriminator :type

# Triggered when a new video transformation request is accepted for processing. This event confirms that ImageKit has received and queued your transformation request. Use this for debugging and tracking transformation lifecycle.
variant -> { Imagekitio::VideoTransformationAcceptedEvent }

Expand Down
2 changes: 2 additions & 0 deletions lib/imagekitio/models/unwrap_webhook_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ module Models
module UnwrapWebhookEvent
extend Imagekitio::Internal::Type::Union

discriminator :type

# Triggered when a new video transformation request is accepted for processing. This event confirms that ImageKit has received and queued your transformation request. Use this for debugging and tracking transformation lifecycle.
variant -> { Imagekitio::VideoTransformationAcceptedEvent }

Expand Down
2 changes: 1 addition & 1 deletion lib/imagekitio/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Imagekitio
VERSION = "4.0.0"
VERSION = "4.0.1"
end
2 changes: 2 additions & 0 deletions manifest.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
dependencies:
- English
- base64
- cgi
- date
- erb
- etc
- json
- net/http
- openssl
- pathname
- rbconfig
- securerandom
Expand Down
5 changes: 5 additions & 0 deletions rbi/imagekitio/internal/transport/base_client.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ module Imagekitio
private def auth_headers
end

# @api private
sig { returns(String) }
private def user_agent
end

# @api private
sig { returns(String) }
private def generate_idempotency_key
Expand Down
8 changes: 6 additions & 2 deletions rbi/imagekitio/internal/transport/pooled_net_requester.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ module Imagekitio

class << self
# @api private
sig { params(url: URI::Generic).returns(Net::HTTP) }
def connect(url)
sig do
params(cert_store: OpenSSL::X509::Store, url: URI::Generic).returns(
Net::HTTP
)
end
def connect(cert_store:, url:)
end

# @api private
Expand Down
12 changes: 8 additions & 4 deletions rbi/imagekitio/internal/type/base_model.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module Imagekitio
#
# Assumes superclass fields are totally defined before fields are accessed /
# defined on subclasses.
sig { params(child: T.self_type).void }
sig { params(child: Imagekitio::Internal::Type::BaseModel).void }
def inherited(child)
end

Expand Down Expand Up @@ -276,9 +276,13 @@ module Imagekitio

# Create a new instance of a model.
sig do
params(data: T.any(T::Hash[Symbol, T.anything], T.self_type)).returns(
T.attached_class
)
params(
data:
T.any(
T::Hash[Symbol, T.anything],
Imagekitio::Internal::Type::BaseModel
)
).returns(T.attached_class)
end
def self.new(data = {})
end
Expand Down
2 changes: 2 additions & 0 deletions sig/imagekitio/internal/transport/base_client.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ module Imagekitio

private def auth_headers: -> ::Hash[String, String]

private def user_agent: -> String

private def generate_idempotency_key: -> String

private def build_request: (
Expand Down
5 changes: 4 additions & 1 deletion sig/imagekitio/internal/transport/pooled_net_requester.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ module Imagekitio

DEFAULT_MAX_CONNECTIONS: Integer

def self.connect: (URI::Generic url) -> top
def self.connect: (
cert_store: OpenSSL::X509::Store,
url: URI::Generic
) -> top

def self.calibrate_socket_timeout: (top conn, Float deadline) -> void

Expand Down
2 changes: 1 addition & 1 deletion test/imagekitio/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_client_redirect_307

assert_requested(:any, "http://localhost/redirected", times: Imagekitio::Client::MAX_REDIRECTS) do
assert_equal(recorded.method, _1.method)
assert_equal(recorded.body, _1.body)
# assert_equal(recorded.body, _1.body) skipping, since the request body is multipart encoded
assert_equal(
recorded.headers.transform_keys(&:downcase).fetch("content-type"),
_1.headers.transform_keys(&:downcase).fetch("content-type")
Expand Down
Loading