Skip to content

Commit ecaee4c

Browse files
workos-tars[bot]Horizon Botgjtorikian
authored
docs: clarify Idempotency-Key is only honored on audit log event creation (#520)
Co-authored-by: workos-tars[bot] <workos-tars[bot]@users.noreply.github.com> Co-authored-by: Horizon Bot <horizon-bot@workos.com> Co-authored-by: Garen Torikian <gjtorikian@users.noreply.github.com>
1 parent e4c731c commit ecaee4c

1 file changed

Lines changed: 15 additions & 14 deletions

File tree

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,7 @@ gem "workos"
2525

2626
## Configuration
2727

28-
To use the library, provide your WorkOS API key as `WORKOS_API_KEY` and, for AuthKit and SSO flows, your client ID as `WORKOS_CLIENT_ID`:
29-
30-
```sh
31-
WORKOS_API_KEY=sk_test_123 WORKOS_CLIENT_ID=client_123 ruby app.rb
32-
```
33-
34-
Or configure the SDK in an initializer:
28+
Store your WorkOS API key (and, for AuthKit and SSO flows, your client ID) in environment variables such as `WORKOS_API_KEY` and `WORKOS_CLIENT_ID`, then pass them to the SDK explicitly. The SDK does not read these environment variables automatically — configure it in an initializer:
3529

3630
```ruby
3731
# /config/initializers/workos.rb
@@ -77,6 +71,7 @@ tenant_b.organizations.list_organizations
7771
```ruby
7872
public_client = WorkOS::PublicClient.create(client_id: "client_123")
7973
url, verifier, state = public_client.user_management.get_authorization_url_with_pkce(
74+
provider: "authkit",
8075
redirect_uri: "https://example.com/callback"
8176
)
8277
```
@@ -93,20 +88,22 @@ on_worker_boot { WorkOS.reset_client }
9388

9489
## Per-request options
9590

96-
Every API call accepts `request_options:` for per-call overrides:
91+
Every method that makes an HTTP request accepts `request_options:` for per-call overrides (local URL-building helpers such as `get_authorization_url` and `get_logout_url` do not):
9792

9893
```ruby
9994
organization = WorkOS.client.organizations.get_organization(
10095
id: "org_123",
10196
request_options: {
10297
timeout: 10,
103-
extra_headers: {"X-Request-Source" => "admin"},
104-
idempotency_key: "org-create-123"
98+
extra_headers: {"X-Request-Source" => "admin"}
10599
}
106100
)
107101
```
108102

109-
`Idempotency-Key` is only sent when you provide `request_options[:idempotency_key]`, or when the SDK retries a mutating request after a transient failure.
103+
`Idempotency-Key` is only sent on `POST`, `PUT`, and `PATCH` requests — either when you provide `request_options[:idempotency_key]`, or auto-generated when the SDK retries one of those requests after a transient failure. It is never attached to `GET` or `DELETE` requests.
104+
105+
> [!NOTE]
106+
> The WorkOS API currently honors `Idempotency-Key` only on the [Create Audit Log Event](https://workos.com/docs/reference/audit-logs/event) endpoint (`audit_logs.create_event`). Other endpoints accept the header but do not deduplicate requests, so a retried mutation elsewhere can still create a duplicate.
110107
111108
## Usage Examples
112109

@@ -155,8 +152,8 @@ ruby -rsecurerandom -e 'puts SecureRandom.base64(32)'
155152
```
156153

157154
Anything shorter than 32 bytes (including `nil` or `""`) raises
158-
`ArgumentError` at SDK init time — sealing or unsealing will not silently
159-
proceed with a weakened key.
155+
`ArgumentError` as soon as you load, seal, or unseal a session — sealing or
156+
unsealing will not silently proceed with a weakened key.
160157

161158
### Verify a webhook
162159

@@ -196,14 +193,18 @@ end
196193

197194
## Error Handling
198195

199-
The SDK raises typed errors for API and transport failures.
196+
The SDK raises typed errors for API failures (`WorkOS::APIError` and
197+
subclasses) and transport failures (`WorkOS::APIConnectionError`). Both
198+
inherit from `WorkOS::Error`.
200199

201200
```ruby
202201
begin
203202
WorkOS.client.organizations.get_organization(id: "org_123")
204203
rescue WorkOS::APIError => e
205204
warn "#{e.class}: #{e.message}"
206205
warn "status=#{e.http_status} request_id=#{e.request_id} code=#{e.code}"
206+
rescue WorkOS::APIConnectionError => e
207+
warn "connection failure: #{e.message}"
207208
end
208209
```
209210

0 commit comments

Comments
 (0)