withToken((string) Settings::get('resend_key')) ->acceptJson()->connectTimeout(3)->timeout(8); } public function usage(): array { $response = $this->request()->get('/usage'); if (!$response->successful()) { throw new \RuntimeException('resend_usage_unavailable'); } return $response->json('emails') ?? []; } public function send(array $payload, string $key): Response { // Automatic HTTP retries would hide uncertainty; retries use the same persisted key/payload. return $this->request()->withHeaders(['Idempotency-Key' => $key])->post('/emails', $payload); } public function retrieve(string $id): array { $response = $this->request()->get('/emails/' . rawurlencode($id)); if (!$response->successful()) { throw new \RuntimeException('resend_status_unavailable'); } return $response->json(); } }