Enhanced cookie handling for API