from http.server import BaseHTTPRequestHandler,HTTPServer
import json,time
RESET=time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime(time.time()+3600))
class Handler(BaseHTTPRequestHandler):
 def do_GET(self):
  self.reply(200,{'files':[{'id':'synthetic-account','auth_index':'0','provider':'claude','email':'demo@example.invalid'}]})
 def do_POST(self):
  body=self.rfile.read(int(self.headers.get('Content-Length','0')))
  if self.path.endswith('/api-call'):
   self.reply(200,{'status_code':200,'body':json.dumps({'five_hour':{'utilization':100,'resets_at':RESET}})})
  else:
   time.sleep(12)
   self.reply(429,{'type':'error','error':{'type':'rate_limit_error','message':'All credentials for model claude-haiku-5-5 are cooling down (last error: rate_limit_error: ...)'}})
 def reply(self,status,data):
  self.send_response(status);self.send_header('Content-Type','application/json');self.send_header('Retry-After','3600');self.end_headers();self.wfile.write(json.dumps(data).encode())
HTTPServer(('127.0.0.1',18774),Handler).serve_forever()
